【Swift】UISwitchの色を変更する
どういうことか
コレ
――の、 ◯ の部分とかの色を変えたい。
やる
@IBOutlet weak var toggleSwitch: UISwitch!
// 中略
// ◯の部分
toggleSwitch.thumbTintColor = UIColor.black
// ◯じゃない部分
toggleSwitch.onTintColor = UIColor.orange
たとえばスイッチオンのときだけ色を変えたい場合はif文を使えばよい。
// メンバ変数
var toggleSwitchCheck = false
// 中略
if toggleSwitchCheck {
toggleSwitch.setOn(false, animated:true)
toggleSwitchCheck = false
toggleSwitch.thumbTintColor = UIColor.white
} else {
toggleSwitch.setOn(true, animated:true)
toggleSwitchCheck = true
toggleSwitch.thumbTintColor = UIColor.orange
}
完(´・ω・`)
Author And Source
この問題について(【Swift】UISwitchの色を変更する), 我々は、より多くの情報をここで見つけました https://qiita.com/antk/items/e166286675ef98e1b009著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .