willWillLayoutSubviews()
내부에 제가 작성한 UIButton's
메서드 setTileTheme()
을 호출합니다. 결과는 아래에서 볼 수 있습니다 - 중복 UILabel
가 다른 것으로 나타납니다. 나는 이미 viewDidLoad()
등에서 내 방법을 호출하려했지만 도움이되지 않았다.UIButton 내의 중복 된 UILabel
이 문제가 발생하는 이유를 아는 사람이 있습니까?
func setTileTheme(image: UIImage, title: String) {
self.translatesAutoresizingMaskIntoConstraints = false
tintColor = .green
backgroundColor = .white
setBorder(width: 1.5, color: .lightGray)
roundCorners(radius: 5)
self.layer.masksToBounds = true
let width = self.frame.size.width
let height = self.frame.size.height
let offset: CGFloat = width/4.5
let titleLabel = UILabel(frame: CGRect(x: 0.0, y: 0.0, width: width, height: 30))
titleLabel.center = CGPoint(x: width/2, y: height-offset)
titleLabel.text = title
titleLabel.font = titleLabel.font.withSize(15)
titleLabel.textAlignment = .center
titleLabel.textColor = .darkGray
self.insertSubview(titleLabel, at: 0)
imageEdgeInsets = UIEdgeInsets(top: height/8, left: width/4, bottom: height*3/8, right: width/4)
setImage(image, for: .disabled)
setImage(image.withRenderingMode(.alwaysTemplate), for: .normal)
}
도움이되기를 바랍니다 오버라이드 (override) 할 수있는 이미지 뷰의 프레임 자체에 영향을 줍니까? 여러 번. 하단에있는 레이블의 어두운 색에 따르면, 나는 같은 위치에 더 있다고 말하고 싶습니다. 총 3 회 이상 호출되었습니다. 따라서 'titleLabel'대신에 프로퍼티를 사용하십시오. – Larme