Programmatically Create a Padded Button iOS 13 & Swift 5
Inside your view create a button object
Programmatically Create a Padded Button iOS 13 & Swift 5
Inside your view create a button object
let sumbitButton: UIButton = {
let button = UIButton()
Set the inset then the content
button.titleEdgeInsets = UIEdgeInsets(top: 10, left: 20, bottom: 10, right: 20)
button.layer.cornerRadius = 15.0
button.setTitle("Submit", for: .normal)
button.setTitleColor(.blue, for: .normal)
button.backgroundColor = .white
button.sizeToFit()
Attach a function to the button
button.addTarget(self, action: #selector(submitButtonPressed), for: .touchUpInside)
return button
}()
Make sure you declare the function
@objc func submitButtonPressed(){ print("submitted" }
Done
메타데이터
- post_id
- 75f59a0da9ed
- slug
- programmatically-create-a-padded-button-ios-13-swift-5-75f59a0da9ed
- url
- https://medium.com/@ahrchen/programmatically-create-a-padded-button-ios-13-swift-5-75f59a0da9ed
- canonical_url
- https://medium.com/@ahrchen/programmatically-create-a-padded-button-ios-13-swift-5-75f59a0da9ed
- author_url
- https://medium.com/@ahrchen
- status
- ok
- fetched_at
- 2026-07-29 07:39:48