
【徒然iOS】気ままにUIKit10〜UISwitch〜
概要
このマガジンは四十を過ぎたおっさんが、
を参考にStoryboardでiOSアプリを完全に趣味で楽しんでいるだけな記事を気ままに上げてます。
今回
をやります。
前準備
念の為、バックアップ
新しいクラス
ビューコントローラの追加
イニシャルビューの変更
をいつも通り🕺

本題
ラベルとスイッチを追加〜〜〜〜

接続してく〜〜〜〜!

後は、アクション接続のコードブロックに条件式を追加

シミュレータで実行

音楽再生アプリ
なんかでもよく見るON/OFF切り替えでスイッチって名前だけど、
他のプログラミング言語とかSwiftUIでは
トグル
なんて言ったり、、、💦
今回は以上かな。
コード
class UISwitchViewController: UIViewController {
@IBOutlet weak var testSwitchLabel: UILabel!
@IBAction func myUISwitch(_ sender: UISwitch) {
if (sender.isOn) {
testSwitchLabel.text = "ONです。"
} else {
testSwitchLabel.text = "OFFです。"
}
}
}
Apple公式
ここまでやった感想
今の所、パーツ単体なのもあるかもしれないけど、
大きく変化したところはないなあ😝
今までのコードで不明なところとかあれば、
で基本構文は抜粋してまとめてるから参考にしてみてね
12/29 追記
ちなみに、完全に思いつきだけど
なんかを参考にスイッチで作ったビューコントローラを作り替えると

みたいな感じで簡単な音楽アプリも簡単に作れたりするので試してみてね〜〜〜!
12/30 追記
個人的には、まだ記事には書いてない
VerticalStackView
HorizontalStackView
AutoLayout
AVFoundation
なんか使って2時間くらいでこんな感じにしてなった

💃開発環境と閃きさえあれば、無限に作り込めるのでアプリ開発は楽しい🕺