1
사용자 지정 UINavigationBar를 작성하려고했지만 button.frame 입력에 아무런 영향이 없습니다.Swift 4 - UINavigationBar에 추가 할 때 UIButton 크기를 제어 할 수 없습니다.
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "I_sent"), for: .normal)
button.addTarget(self, action: #selector(action), for: .touchUpInside)
// This doesn't seem to have an effect:
button.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
button.contentMode = .scaleAspectFit
let item = UIBarButtonItem(customView: button)
navigationItem.rightBarButtonItem = item
}
@objc func action() {
print("Action")
}
실행하면 코드 (위)과 같이 나타납니다
하지만 그것은 다음과 같이 만들려고 노력하고 있어요 :
이 어떤 도움이 대단히 감사합니다!
button.widthAnchor.constraint(equalToConstant: button.frame.size.width).isActive = true
button.heightAnchor.constraint(equalToConstant: button.frame.size.height).isActive = true
는 희망이 도움이 :
효과가있었습니다. 정말 고맙습니다! – Jake
@Jake 해피 코딩 :-) –