IOS--UISwitch的使用方法

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   使用   sp   

IOS--UISwitch的使用方法詳細 (2013-08-24 11:09:38) 轉載▼
標籤: uiswitch switch 選擇控制項 ios it 分類: iOS--UI

// UISwitch的使用

    UISwitch *oneSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(20, 20, 0, 0)]; // 預設尺寸為79 * 27。

    oneSwitch.backgroundColor = [UIColor greenColor]; // 設定背景色

    oneSwitch.alpha = 1.0; // 設定透明度 範圍在0.0-1.0之間 0.0是完全透明

    

    oneSwitch.onTintColor = [UIColor redColor]; // 在oneSwitch開啟的狀態顯示的顏色 預設是blueColor

    oneSwitch.tintColor = [UIColor purpleColor]; // 設定關閉狀態的顏色

    oneSwitch.thumbTintColor = [UIColor blueColor]; // 設定開關上左右滑動的小圓點的顏色

    

    // oneSwitch.on = YES; // // 設定初始狀態 直接設定為on,你不回觀察到它的變化

    [oneSwitch setOn:YES animated:YES]; // 設定初始狀態,與上面的不同是當你看到這個控制項的時候再開始設定為on,你會觀察到他的變化

    

    

    oneSwitch.onImage = [UIImage imageNamed:@"min.png"]; // 開啟狀態顯示的圖片

    oneSwitch.offImage = [UIImage imageNamed:@"max.png"]; // 關閉狀態下的圖片

    

    [oneSwitch addTarget:self action:@selector(oneSwitchValueChanged:)forControlEvents:UIControlEventValueChanged]; // 添加事件監聽器的方法

 

    // 添加到view並釋放記憶體

    [self.view addSubview:oneSwitch];

    [oneSwitch release], oneSwitch = nil;

 

 

 

 

#pragma mark - 實現UISwitch監聽的方法

- (void)oneSwitchValueChanged:(UISwitch *) sender {

    NSLog(@"%@", sender.isOn ? @"ON" : @"OFF");

}

 

IOS--UISwitch的使用方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.