UISwitchの基礎の基礎?

UISwichをアクション接続した時の書き方。

- (IBAction)alertSwichOnOff:(UISwitch *)sender {
    
    //UISwitchはBOOL型なのでYES,NOとして直接指定できる。
    self.timeField.enabled = self.alertSwitch.on;
    self.alertSegment.enabled = self.alertSwitch.on;
    
    //そうでない場合はif-elesで指定する。
    if (self.alertSwitch.on) {
        self.timeField.alpha = 1;
    } else {
        self.timeField.alpha = 0.5;
    }
}

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です