作者热门文章
- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我有一个简单的查询,我需要给 UIButton 文本和颜色加下划线。我有 uibutton 的下划线文本,但是关于色调它不起作用。我已经从 xib 设置了色调颜色,它不是从那里获取的。下面是我的代码。
NSMutableAttributedString *commentString = [[NSMutableAttributedString alloc] initWithString:@"Testing"];
[commentString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [commentString length])];
[_helpWithLoginLabel setAttributedTitle:commentString forState:UIControlStateNormal];
最佳答案
在 Swift 中:
let attributes = [NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue]
let attributedText = NSAttributedString(string: button.currentTitle!, attributes: attributes)
button.titleLabel?.attributedText = attributedText
关于iphone - 如何在 iOS 中为 uibutton 的文本和颜色添加下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19256907/
我是一名优秀的程序员,十分优秀!