1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Swift】UIButtonに画像を表示させる方法

Last updated at Posted at 2021-11-09

SwiftでUIButtonに画像を表示させる方法。

let imageButton = UIButton()

imageButton.setImage(UIImage(named:"sample")!, for: .normal)

self.view.addSubview(imageButton)

UIbuttonにsetImage関数を割り当てるだけ。

リファレンスによるとsetImageでは以下の宣言がなされる。

func setImage(_ image: UIImage?, 
          for state: UIControl.State)
//image
//The image to use for the specified state.

//state
//The state that uses the specified image. The values are described in UIControl.State.

参考

Swiftのお役立ち情報

1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?