8
8

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.

UISwitchがOFFの時の背景色カスタマイズ方法

Posted at

UISwitchにはcolorを設定するプロパティが3つあります。

UISwitch *sw = [UISwitch new];
sw.tintColor = [UIColor blueColor];
sw.onTintColor = [UIColor redColor];
sw.thumbTintColor = [UIColor greenColor];

offの時には青くて、onの時には赤くて、ツマミが緑のSwitchができました。

IMG_4728.PNG
IMG_4729.PNG

…offのときの背景色、白い。
黒のほうがいいので、backgroundColorを設定します。

sw.backgroundColor = [UIColor blackColor];

IMG_4730.PNG
IMG_4731.PNG

!!?

こんなときはlayer.cornerRadiusを設定しましょう。

sw.layer.cornerRadius = sw.frame.size.height/2;

IMG_4732.PNG
IMG_4733.PNG

できあがり。

8
8
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?