728x90
240422
로그인 버튼을 누르면 지정해 놓은 뷰로 이동해 보려한다
lazy var loginButton: UIButton = {
var button = UIButton(type: .custom)
button.setTitle("로그인", for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .bold)
button.backgroundColor = .clear
button.layer.cornerRadius = 5
button.clipsToBounds = true
button.layer.borderWidth = 1 // 버튼의 테두리 두께 설정
button.layer.borderColor = UIColor.white.cgColor // 버튼의 테두리 색 설정
button.isEnabled = true // 버튼의 동작 설정 (처음에는 동작 off)
//**********************************//
button.addTarget(self, action: #selector(loginButtonClicked), for: .touchUpInside)
return button
}()
@objc func loginButtonClicked() {
print("clicked button")
let mainPageViewController = MainPageViewController()
navigationController?.pushViewController(mainPageViewController, animated: true)
}
addTarget 메소드로 구현해주면 된다
@objc func 함수에서 원하는 뷰를 지정하여 주면 끝!
여담.
버튼에 isEnabled = false 로 해놓고 왜 안되지 !! 이랬음 ㅋㅋ
버튼 동작을 허용 해줘야해~
728x90
'iOS Swift > Study' 카테고리의 다른 글
Swift codebase UI 그리기 ScrollView 넣기! (0) | 2024.04.25 |
---|---|
Swift codebase UI 그리기 CollectionView (0) | 2024.04.25 |
스토리보드 없이 Custom Navigation Controller 연결하기 (0) | 2024.04.22 |
To Do List 만들기 (1) alret 창 띄우고 할 일 적기 (0) | 2024.03.28 |
Swift 숫자 맞추기 게임 1 (1) | 2024.03.12 |
댓글