[英]Bold font style for custom font in iOS application
I have a custom font and it doesn't include bold face. 我有一个自定义字体,它不包含黑体字。 I have no problem using it in web and Android since they use faux bold but, I don't know how can I make it bold in iOS.
我在网络和Android上使用它没有问题,因为它们使用的是人造粗体,但是我不知道如何在iOS中将其设为粗体。 I want to know if there is a way to make faux bold in iOS or any tool to create a bold font face from normal one using techniques that browsers use.
我想知道是否有一种方法可以在iOS中使人造粗体或任何工具使用浏览器使用的技术从普通工具中创建粗体。
You could use NSAttributedString
to stroke text and make them bold. 您可以使用
NSAttributedString
描边文本并使它们NSAttributedString
粗体。
Try this code below: 请尝试以下代码:
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)];
Hope this help. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.