Search code examples
swiftuibuttonautolayoutstoryboard

Can I set offset position on Storyboard?


Can I write like the code below on Storyboard?

let button = UIButton()
button.titleLabel.center = CGPoint(x:button.titleLabel.center.x, y:button.titleLabel.center.y + 30)

Solution

  • Look into UIEdgeInsets and the UIButton property titleEdgeInsets.

    button.titleLabelInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 30)
    

    Depending on your exact needs and code, this should do what you need. (FYI - there is a imageEdgeInsets also.)