셀렉트바 타이틀 좌우 이미지 버튼 생성 방법

let button: UIButton = UIButton(type: UIButtonType.custom)

button.setImage(UIImage(named: “arrow_right.png”), for: UIControlState.normal)

button.addTarget(self, action: #selector(CounselorTabController.OnMenuClicked), for: UIControlEvents.touchUpInside)

button.widthAnchor.constraint(equalToConstant: 20.0).isActive = true

button.heightAnchor.constraint(equalToConstant: 20.0).isActive = true

let barButton = UIBarButtonItem(customView: button)

 

 

let homeButton : UIBarButtonItem = UIBarButtonItem(image: UIImage(named: “arrow_right”), style: UIBarButtonItemStyle.plain, target: self, action: nil)

 

let logButton : UIBarButtonItem = UIBarButtonItem(title: “arrow_right.png”, style: UIBarButtonItemStyle.plain, target: self, action: “”)

 

let icon = UIImage(named: “active_dot”)

let iconSize = CGRect(origin: CGPoint.zero, size: CGSize(width: 10, height: 10))

let iconButton = UIButton(frame: iconSize)

iconButton.setBackgroundImage(icon, for: .normal)

let barButton2 = UIBarButtonItem(customView: iconButton)

 

iconButton.addTarget(self, action: #selector(OnMenuClicked), for: .touchUpInside)

 

self.navigationItem.leftBarButtonItem = barButton

//self.navigationItem.rightBarButtonItem = logButton

self.navigationItem.rightBarButtonItem = barButton2

카테고리 iOS

답글 남기기