Sebastian
Sebastian

Reputation: 73

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.

I'm missing something, please help

extension: 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:

enter image description here

Upvotes: 0

Views: 2266

Answers (1)

mahan
mahan

Reputation: 14925

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.

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)

Upvotes: 1

Related Questions