Apple’s doc for these extensions实际上包括常量(在最底层),包括UITextAttributeTextShadowColor和UITextAttributeTextShadowOffset,这意味着它是可能的,但是我在实际的方法中没有看到任何可能的用法.
解决方法
> UITextAttributeTextShadow …键用于在使用文本属性字典时使用例如UIAppearance方法:
NSDictionary *attributes = @{UITextAttributeTextShadowColor : [UIColor blackColor],UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(2.0,0.0)],UITextAttributeTextColor : [UIColor yellowColor]}; [[UINavigationBar appearance] setTitleTextAttributes:attributes];
UITextAttributeTextShadow …键设计仅用于接受文本属性字典的那些方法.
>绘制文本字符串时最接近的等效键是使用带有NSShadowAttributeName键的归因字符串:
- (void)drawRect:(CGRect)rect { UIFont *font = [UIFont systemFontOfSize:50]; NSShadow *shadow = [[NSShadow alloc] init]; shadow.shadowColor = [UIColor blackColor]; shadow.shadowBlurRadius = 0.0; shadow.shadowOffset = CGSizeMake(0.0,2.0); NSDictionary *attributes = @{NSShadowAttributeName : shadow,NSForegroundColorAttributeName : [UIColor yellowColor],NSFontAttributeName : font}; NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:@"this has shadows" attributes:attributes]; [attributedText drawInRect:rect]; }
如果您担心影子算法能够进行贝塞尔曲线阴影的性能,那么NSShadow可能会受到影响.但是做一些基准测试,改变shadowBlurRadius会显着影响性能.例如,在较慢的iPhone 3GS上,使用shadowBlurRadius 10.0的复杂多行文本的旋转实现了31 fps的帧速率,但是将shadowBlurRadius更改为0.0则会产生60 fps的帧速率.
使用阴影模糊半径0.0的底线消除了贝塞尔生成阴影的大部分(如果不是全部)计算开销.
> FYI,通过将CGContextSetShadow的模糊值设置为0.0,我也经历了类似的性能提升,就像我在上面的归因文本转换一样.
底线,我不认为你应该害怕基于贝塞尔的阴影的计算开销,只要您使用0.0的模糊半径.我不会惊讶,如果自己写两次文本,一次为阴影,再次为前景色,甚至可能会更有效率,但我不知道差异是否可以观察到.但是我不知道会为你做什么API调用(除了CGContextSetShadow,模糊为0.0).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。