[英]ios 6.0 setAttributedText crash
- (IBAction)pinFieldChanged:(id)sender {
UITextField *pinField = sender;
float kerninig = 76.0;
NSAttributedString *attributedString =
[[NSAttributedString alloc]
initWithString:pinField.text
attributes:
@{
NSFontAttributeName : [UIFont fontWithName:@"Helvetica Neue" size:36],
NSForegroundColorAttributeName : [UIColor colorWithRed:130.0/255.0 green:130.0/255.0 blue:130.0/255.0 alpha:1.0],
NSKernAttributeName : @(kerninig)
}];
if ([pinField respondsToSelector:@selector(setAttributedText:)]) {
[pinField setAttributedText:attributedString];
}
}
嘗試將屬性文本設置為文本字段時,我的應用在ios6.0下崩潰,盡管此選擇器在iOS 6.0及更高版本中可用
您能告訴我為什么會發生這種情況嗎?
提前致謝!)
iOS5可能期望CTFont如此使用
NSString* s = @"Yo ho ho and a bottle of rum!";
NSMutableAttributedString* mas = [[NSMutableAttributedString alloc] initWithString:s];
__block CGFloat f = 18.0;
CTFontRef basefont = CTFontCreateWithName((CFStringRef)@"Baskerville", f, NULL);
在iOS 6以下使用
NSAttributedString *stringValue= [[NSAttributedString alloc] initWithString:@"cocoalibrary.blogspot.com" attributes:@{NSForegroundColorAttributeName: [UIColor redColor]}];
除了IOS 6,NSAttributedString在下面不可用。請參見此鏈接 ,您可以找到此行。
在iOS 6及更高版本中,您可以使用屬性字符串在文本視圖,文本字段和某些其他控件中顯示格式化的文本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.