LoginSignup
1
0

More than 1 year has passed since last update.

UIButtonのsetBackgroundImageが効かない

Posted at

[問題]

swift
otherButton.setBackgroundImage(UIImage(named: "other"), for: .normal)

こんな感じで書いていたsetBackgroundImageのコードが反映されず、なかなか時間かかってしまったので備忘録です。

[解決法]

以下の画像のように、storyboardのUIButtonの設定部にある Button>StyleをDefaultにすると無事にコードが反映されるようになりました。

image.png

[原因]

iOS15に対応したXcode13からの仕様変更によるもので、StoryboardでUIButtonを作成すると自動的に 「Plain」が選択されることが原因のようです。
UIButtonに新しく4つのタイプ(Plain, Gray, Tinted, Filled)が追加されました。

参考にした記事
https://zenn.dev/koux99/articles/1abce4ed574b23

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0