如何实现这个UI/UX设计,在iOS的UIButton对象
看的爽UI绝招“忘记你的登录信息?在获得帮助签约。”按钮。他们是如何将按钮分成可点击和不可点击的部分的?如果它不是一个按钮,而是一个标签和一个按钮,那么他们是如何让按钮的第二行被居中的?
使用归因字符串设置按钮标题。请参阅下面的代码以供参考。
func attributedText(){
// create attributed string
let attributedString = NSMutableAttributedString(string:"Don't have an account? ")
let myString = "Sign Up"
let myAttribute = [ NSForegroundColorAttributeName: UIColor(red: 194/255, green: 159/255, blue: 74/255, alpha: 1.0) ]
let myAttrString = NSAttributedString(string: myString, attributes: myAttribute)
attributedString.append(myAttrString)
myCustomButton.setAttributedTitle(attributedString, for: .normal)
}
但不会是令整个字符串的按钮,而不是'注册'字样? –
@Manan这是被接受的答案,但是当用户点击单词'details?''ils?'时,将会调用按钮点击事件。所以也许这是不正确的做法。 –
@ ChintaN-Maddy-Ramani是的,这是真的。但是我们只能做一件事情,或者使UI成为现实。或者在右边第二行包含“in”,这样它就不会覆盖“细节”。有没有其他方法? – Amanpreet
我已经评论过按预期工作的库 –
这是一个标签和一个没有蓝色文本上方名称的按钮,因此将一个标签拖放到故事板并将其连接到您的swift文件(我将它命名为labelText)和一个位于所需文本上方的按钮。
那么你的viewDidLoad函数中把这个行:
// You can change the color as you want
let color: UIColor = UIColor(red: 2/255.0, green: 202/255.0, blue: 246/255.0, alpha: 1.0)
let string_to_color = "Get help signing in."
let titleStr: String = labelText.text!
let range: NSRange = (titleStr as NSString).rangeOfString(string_to_color)
let str: NSMutableAttributedString = NSMutableAttributedString(string: titleStr)
str.addAttribute(NSForegroundColorAttributeName, value: color, range: range)
//Below line is if you want a line under your colored text
//str.addAttribute(NSUnderlineStyleAttributeName, value: NSUnderlineStyle.StyleSingle.rawValue, range: range)
labelText.attributedText = str
,现在你可以走了。
快乐编码。
看起来像网页 – sage444
尝试[TTTAttributedLabel(https://github.com/TTTAttributedLabel/TTTAttributedLabel)或[FRHyperLabel(https://github.com/null09264/FRHyperLabel) –