티스토리 뷰

iOS

iOS) UIButton programmatically

hyun99999 2021. 7. 21. 21:04
728x90
반응형

UIButton 코드로 짜기

let bookBtn = UIButton()
//title
bookBtn.setTitle("예매율순", for: .normal)

//title color
bookBtn.setTitleColor(.black, for: .normal)

//title fontsize
bookBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12)

//imageview image
bookBtn.setImage(UIImage(systemName: "circle.fill"), for: .normal)

//imageview image size
bookBtn.setPreferredSymbolConfiguration(.init(pointSize: 3, weight: .regular, scale: .default), forImageIn: .normal)

//imageview image color
bookBtn.tintColor = .black

//UIButton insets
bookBtn.titleEdgeInsets = .init(top: .zero, left: 8, bottom: .zero, right: .zero)

//UIButton add action
bookBtn.addTarget(self, action: #selector(touchBookBtn), for: .touchUpInside)
728x90
반응형
댓글
최근에 올라온 글
최근에 달린 댓글
글 보관함
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
링크
Total
Today
Yesterday