iOS应用程序中的自定义字体的粗体字体样式
问题描述:
我有自定义字体,但不包含粗体。我在使用网页和Android时没有问题,因为它们使用了粗体,但是,我不知道如何在iOS中将它变成粗体。 我想知道是否有一种方法可以在iOS中制作粗体或使用浏览器使用的技术从任何工具创建粗体字体。iOS应用程序中的自定义字体的粗体字体样式
答
您可以使用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)];
希望这有助于。
感谢您的回复。我这样做,但它只是给我的轮廓,它里面是空的。 – Emad
我已经修复了代码,试试并让我知道。 –
是它现在的工作。谢谢。 – Emad