[tvOS]UIButtonのBackgroundImageが先頭に表示される問題を解消する
tvOSのUIButtonのBackgroundImageはなぜかimageViewよりも前にあるので、セットすると文字やsetImage,stateした画像が隠れて見えなくなります。
上が修正済みのボタン、下が既存のUIButton
レイヤー構造
UIImageViewが二枚あって分かりにくいですが、backgroundImageのImageViewが先頭に来てしまっています。
class FixedButton : UIButton {
override func layoutSubviews() {
super.layoutSubviews()
if let iv = imageView {
iv.superview?.bringSubviewToFront(iv)
}
if let lbl = titleLabel {
lbl.superview?.bringSubviewToFront(lbl)
}
}
}
上記のようにUILabelとUIImageViewを先頭に移動させれば解決します。(backgroundImageのImageViewは直接参照できないのでこれで)
Author And Source
この問題について([tvOS]UIButtonのBackgroundImageが先頭に表示される問題を解消する), 我々は、より多くの情報をここで見つけました https://qiita.com/noppefoxwolf/items/e2eb5ae7902dc957297b著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .