UITextView与NSStrokeColorAttributeName问题归档文字

我想在iOS 6中添加描边到UITextView的文本。当iOS 6添加支持的属性到UILabel,UITextField,UITextView,我创build一个NSMutableAttributedString并将其设置为UITextView的属性文本。 代码如下:

- (void)viewDidLoad { [super viewDidLoad]; NSMutableAttributedString *title; title = [[NSMutableAttributedString alloc] initWithString:@"Visual comparison"]; int length = title.length; [title addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Noteworthy-Bold" size:36] range:NSMakeRange(0,length)]; [title addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,length)]; [title addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,length)]; [title addAttribute:NSStrokeWidthAttributeName value:@-3.0 range:NSMakeRange(0,length)]; UITextView *label = [[UITextView alloc] initWithFrame:self.view.bounds]; label.attributedText = title; [self.view addSubview:label]; } 

但是它不起作用,UITextView的文本不被抚摸或填充。 用UILabel或UITextFieldreplaceUITextView一切都会正确。

如果您将NSStrokeWidthAttributeName的值设置为@ 3.0并注释一行,如下所示:

 - (void)viewDidLoad { [super viewDidLoad]; NSMutableAttributedString *title; title = [[NSMutableAttributedString alloc] initWithString:@"Visual comparison"]; int length = title.length; [title addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Noteworthy-Bold" size:36] range:NSMakeRange(0,length)]; [title addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,length)]; // [title addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,length)]; [title addAttribute:NSStrokeWidthAttributeName value:@3.0 range:NSMakeRange(0,length)]; UITextView *label = [[UITextView alloc] initWithFrame:self.view.bounds]; label.attributedText = title; [self.view addSubview:label]; } 

UITextView的文本是完全抚摸。

如果你添加这些行:

 - (void)viewDidLoad { [super viewDidLoad]; NSMutableAttributedString *title; title = [[NSMutableAttributedString alloc] initWithString:@"Visual comparison"]; int length = title.length; [title addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Noteworthy-Bold" size:36] range:NSMakeRange(0,length)]; [title addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,length)]; if (length % 2 == 0) { length = length / 2 - 1; } else { length = length / 2; } [title addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,length)]; [title addAttribute:NSStrokeWidthAttributeName value:@-3.0 range:NSMakeRange(0,length)]; UITextView *label = [[UITextView alloc] initWithFrame:self.view.bounds]; label.attributedText = title; [self.view addSubview:label]; } 

然后UITextView的文本将再次正确。

任何人知道为什么