简体   繁体   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];
    }

}

My app is crashing under ios6.0 when i'm trying to set attributed text to text field, though this selector is available iOS 6.0 and later 尝试将属性文本设置为文本字段时,我的应用在ios6.0下崩溃,尽管此选择器在iOS 6.0及更高版本中可用

Can you give me any idea why this could happen? 您能告诉我为什么会发生这种情况吗?

Thanks in advance!) 提前致谢!)

iOS5 may be expects a CTFont so use 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 https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/iOS5bookExamples/ch23p689styledText1/p579p593styleText1/RootViewController.m

use below ios 6 在iOS 6以下使用

 NSAttributedString *stringValue= [[NSAttributedString alloc] initWithString:@"cocoalibrary.blogspot.com" attributes:@{NSForegroundColorAttributeName: [UIColor redColor]}];

NSAttributedString is not available below than IOS 6. See this link , you can found this line. 除了IOS 6,NSAttributedString在下面不可用。请参见此链接 ,您可以找到此行。

In iOS 6 and later you can use attributed strings to display formatted text in text views, text fields, and some other controls 在iOS 6及更高版本中,您可以使用属性字符串在文本视图,文本字段和某些其他控件中显示格式化的文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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