gpt4 book ai didi

iphone - 如何在 iOS 中为 uibutton 的文本和颜色添加下划线

转载 作者:技术小花猫 更新时间:2023-10-29 10:57:09 26 4
gpt4 key购买 nike

我有一个简单的查询,我需要给 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com