NSAttributedString使用NSStrokeColorAttributeName和NSStrokeWidthAttributeName设置绘制无描边

时间:2013-10-27 19:25:14

标签: ios objective-c nsattributedstring

下面这个例子应该与填充一起绘制一个笔划,但事实并非如此。怎么了?根据Apple的文档,我使用负值来显示stoke。如果我将其设为正值,则文本完全消失。

UITextView *rte = [[UITextView alloc]initWithFrame:
                                  CGRectMake(50,50,100,100)];

[self.view addSubview:rte];
NSDictionary *typingAttributes = @{
                                   NSFontAttributeName: [UIFont fontWithName:@"Helvetica-Bold" size:20.0f],
                                   NSForegroundColorAttributeName : [UIColor redColor],
                                   NSStrokeColorAttributeName : [UIColor yellowColor],
                                   NSStrokeWidthAttributeName : [NSNumber numberWithFloat:-2.0]
                                   };
NSAttributedString *str = [[NSAttributedString alloc]
                           initWithString:@"Enter text here..."
                           attributes:typingAttributes];
rte.attributedText = str;

1 个答案:

答案 0 :(得分:1)

我在iOS 7.0.3模拟器中尝试过您的代码并获得了结果: enter image description here

它在iOS 6中不起作用。我认为这是一个错误。 This approach is working

抱歉,我没有任何解释为什么在iOS 6中它不起作用。