繁体   English   中英

iOS 6.0 setAttributedText崩溃

[英]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);

https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/iOS5bookExamples/ch23p689styledText1/p579p593styleText1/RootViewController.m

在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM