Nsattributedstring 更改脚本/Xib文件中标题类型的标题标签
问题: 我使用下面的代码在运行时更改UIButton的标题和下划线Nsattributedstring 更改脚本/Xib文件中标题类型的标题标签,nsattributedstring,Nsattributedstring,问题: 我使用下面的代码在运行时更改UIButton的标题和下划线 [btnTemp setTitle:@"Test" forState:UIControlStateNormal]; 我有以下问题: 下划线不显示 头衔不变 标题颜色为显示默认黑色 为了克服这个问题,我实现了以下代码: NSDictionary *attribs = @{NSForegroundColorAttributeName: _btnTemp.titleLabel.textColor, NSFontAttributeNa
[btnTemp setTitle:@"Test" forState:UIControlStateNormal];
我有以下问题:
NSDictionary *attribs = @{NSForegroundColorAttributeName: _btnTemp.titleLabel.textColor,
NSFontAttributeName: _btnTemp.titleLabel.font,
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)
};
NSAttributedString *strAttributed = [[NSAttributedString alloc] initWithString:@"Test" attributes:attribs];
[btnTemp setAttributedTitle:strAttributed forState:UIControlStateNormal];
尝试将
@(NSUnderlineStyleSingle)
替换为@(NSUnderlineStyleSingle | NSUnderlinePatternSolid)
?还有,“标题不变”意味着你设置了一个与“测试”不同的文本,而“测试”甚至没有显示?你的代码叫什么?\u btnTemp
是否为零?在btnTemp
之后使用。是同一个对象吗?@Larme尝试编写与我提供的代码相同的代码,这对我来说是正确的。希望对你有帮助。