2016-07-31 71 views
0

我有自定義字體,但不包含粗體。我在使用網頁和Android時沒有問題,因爲它們使用了粗體,但是,我不知道如何在iOS中將它變成粗體。 我想知道是否有一種方法可以在iOS中製作粗體或使用瀏覽器使用的技術從任何工具創建粗體字體。iOS應用程序中的自定義字體的粗體字體樣式

回答

2

您可以使用NSAttributedString來描邊文本並使其變爲粗體。

試試下面這段代碼:

NSString *string = @"Hello World"; 
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:string]; 
    NSDictionary *attributes = @{ 
         NSStrokeWidthAttributeName: @-5.0, //value for making bold, higher negative number bolder text 
         NSStrokeColorAttributeName:[UIColor blackColor], 
         NSForegroundColorAttributeName:[UIColor blackColor], 
         NSFontAttributeName:[UIFont fontWithName:@"Your font name" size:20] 
          }; 
    [attrString addAttributes:attributes range:NSMakeRange(0, string.length)]; 

希望這有助於。

+0

感謝您的回覆。我這樣做,但它只是給我的輪廓,它裏面是空的。 – Emad

+0

我已經修復了代碼,試試並讓我知道。 –

+0

是它現在的工作。謝謝。 – Emad

相關問題