简体   繁体   English

将底线添加到 UIButton - Swift

[英]add bottom line to UIButton - Swift

I use the extension to UIButton and I added it to my UIButton but I still can't see the line.我使用 UIButton 的扩展并将其添加到我的 UIButton 但我仍然看不到这条线。

I'm missing something, please help我错过了一些东西,请帮忙

extension: https://gist.github.com/Isuru-Nanayakkara/496d5713e61125bddcf5扩展名: https://gist.github.com/Isuru-Nanayakkara/496d5713e61125bddcf5

my code:我的代码:

    let settingsButton : UIButton = {
    let button = UIButton()
    button.setTitle("Settings", for: .normal)
    button.setTitleColor(.white, for: .normal)

    button.addBorder(side: .Bottom, color: .white, width: 100)
    
    return button
}() 

I want to get something like this:我想得到这样的东西:

在此处输入图像描述

Add a UIView that has [x] points height and same width as the button, and its y position is the same as the height of the button.添加一个UIView ,其高度和宽度与按钮相同,其 y position 与按钮的高度相同。

let frame = CGRect(x: 0, y: button.frame.size.height, width: button.frame.size.width, height: 2)
let borderBottom = UIView(frame: frame)
borderBottom.backgroundColor= UIColor.white
button.addSubview(borderBottom)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM