LoginSignup
1
3

More than 5 years have passed since last update.

UISegmentedControlの背景が透けるの防ぐ

Posted at

UISegmentedControlはデフォルトでは透過するようになっています。単にbackgroundColorを設定するだけだと、四辺の角丸で切り抜いてくれず、四辺に設定した背景色が表示されてしまいます。

ss01.png

そこで以下のようにして対処します。

# 背景色
segmentedControl.backgroundColor = UIColor.cyan
# 選択時の背景
segmentedControl.tintColor = UIColor.gray
# 角丸くり抜き
segmentedControl.clipsToBounds = true
segmentedControl.layer.cornerRadius = 4.0
1
3
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
3