7
7

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 5 years have passed since last update.

UIImageViewのhighlightedべんり

Last updated at Posted at 2015-06-02

前置き

ゲージの表示をImageViewを並べて作っていたのだけど、画像の中身が2つのステートしか持たないのに、コードをみるといちいちUIImageViewの中身をUIImageで差し替えたりしていて無駄だなーと思った。

UIImageViewには、highlightedというプロパティがある。
コレを利用すると2ステートの表示が簡単に切り替えられて便利なのでメモ。

サンプル

let imageView: UIImageView = UIImageView()
imageView.image = UIImage(named: "state1")
imageView.highlightedImage = UIImage(named: "state2")

imageView.highlighted = false // state1が表示される
imageView.highlighted = true  // state2が表示される

簡単!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?