UIButton" setAttributedTitle"显示"(null)"

时间:2016-10-05 14:41:36

标签: ios objective-c uibutton nsattributedstring

按钮显示"(null)"如果使用" setAttributedTitle"。如果使用" setTitle"。

,它可以显示没有属性的正确字符串

知道如何正确显示属性吗?为什么它可以" null"?

// Set current bar button attributes
NSMutableAttributedString *currentBarAttributedString = [[NSMutableAttributedString alloc] init];
[currentBarAttributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"REQUEST\n"
                                                                         attributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleNone)}]];
[currentBarAttributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"EQUIPMENT"
                                                                         attributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)}]];
// Initialize buttons and set titles
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 setAttributedTitle:currentBarAttributedString forState:UIControlStateNormal];

0 个答案:

没有答案