UIFontDescriptor *bodyFontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
UIFontDescriptor *italicBoldDescriptor = [bodyFontDescriptor fontDescriptorByAddingAttributes:@{UIFontDescriptorTraitsAttribute : @{ UIFontSymbolicTrait: @(UIFontDescriptorTraitItalic | UIFontDescriptorTraitBold)}}];
UIFont *comboFont = [UIFont fontWithDescriptor:italicBoldDescriptor size:0.0];
[self.body.textStorage addAttribute:NSFontAttributeName value:comboFont range:self.body.selectedRange];我的目标是在文本视图中以粗体/斜体显示选定的文本。在做了一些研究之后,这就是我所拥有的,并且它起作用了!但是,我真的不理解代码,尤其是第二行。如果有人能解释一下这段代码到底在做什么,我将不胜感激。此外,我也不理解第二行中发生的字典语法。'|‘字符的语法是什么?我以前从未见过这种情况。非常感谢您的宝贵时间。
发布于 2016-02-04 19:19:30
UIFontDescriptorTraitsAttribute,一个完整描述字体特征的NSDictionary实例。默认值由字体提供。
UIFontDescriptorSymbolicTraits象征性地描述了字体的风格方面。
https://stackoverflow.com/questions/35199390
复制相似问题