2013-07-17 33 views
5

我使用NSAttributedString(和NSMutableAttributeString)通過UIGraphicsBeginPDFContextToFile寫入PDF。當我輸出帶有下劃線屬性的屬性字符串時,下劃線字母下劃線越過下劃線時下劃線被破壞。解決方法所尋找的解決方法:iOS 6 NSAttributedString Descenders Block Underline

下面是一個示例(截屏)顯示,電流輸出:

sample underline image

這裏是建立該樣本屬性串代碼:

NSAttributedString* ftype = 
     [[NSMutableAttributedString alloc] 
        initWithString:@"Dangerous" 
         attributes:@{ 
            NSParagraphStyleAttributeName:pstyle, 
            NSFontAttributeName:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:48.0], 
            NSForegroundColorAttributeName:[UIColor redColor], 
            NSUnderlineStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle] 
            } 
     ]; 

我的客戶和我的喜好是下劃線是連續的,理想情況下移到下邊界下方。

手動繪製下劃線比較困難,因爲我們必須在佈局(有時文本不像上面的示例那樣簡單)計算文本的位置

有沒有人有修復把下劃線要麼a)降低或b)使其連續?

在此先感謝。

回答

2

我知道這是舊的,搜索後發現沒有答案。我找到了解決辦法是在你通過在屬性NSAttributedString initWithString字典:屬性:添加此

NSExpansionAttributeName:@ -0.0001f

這縮放字形,並將其與此少量下劃線甚至似乎不會被削減(當然,它沒有使用我使用的13pt字體)。雖然這看起來不像NSExpansionAttributeName的預期用途,但找不到其他解決方案。