![ios – 如何在使用[UIFont preferredFontForTextStyle:xxx]时选择性地使文本斜体化?,第1张 ios – 如何在使用[UIFont preferredFontForTextStyle:xxx]时选择性地使文本斜体化?,第1张](/aiimages/ios+%E2%80%93+%E5%A6%82%E4%BD%95%E5%9C%A8%E4%BD%BF%E7%94%A8%5BUIFont+preferredFontForTextStyle%EF%BC%9Axxx%5D%E6%97%B6%E9%80%89%E6%8B%A9%E6%80%A7%E5%9C%B0%E4%BD%BF%E6%96%87%E6%9C%AC%E6%96%9C%E4%BD%93%E5%8C%96%EF%BC%9F.png)
UIFont *Font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];NSDictionary *attributes = @{ NSFontAttributename: Font };NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:str attributes:attributes]; 现在我想通过以下方式将attrStr的特定范围斜体化:
- (voID)setAttributes:(NSDictionary *)attrs range:(NSRange)range;
但是因为我从来没有要求过特定的字体,所以我不确定如何去做.
解决方法// Create the normal body style Font UIFont *Font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];// Get the Font's descriptor and add the italics traitUIFontDescriptor *FontDesc = [Font FontDescriptor];FontDesc = [FontDesc FontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic];// Create the italicized Font from the descriptorUIFont *italicsFont = [UIFont FontWithDescriptor:FontDesc size:Font.pointSize];// Create the attributes dictionary that we'll use to italicize parts of our NSMutableAttributedStringNSDictionary *italicsAttributes = @{ NSFontAttributename: italicsFont }; 总结 以上是内存溢出为你收集整理的ios – 如何在使用[UIFont preferredFontForTextStyle:xxx]时选择性地使文本斜体化?全部内容,希望文章能够帮你解决ios – 如何在使用[UIFont preferredFontForTextStyle:xxx]时选择性地使文本斜体化?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)