UISwitch
2015-06-16 14:28
441 查看
// // UISwitchViewController.m // AppUI组件学习 // // Created by 麦子 on 15/6/16. // Copyright (c) 2015年 麦子. All rights reserved. // #import "UISwitchViewController.h" @interface UISwitchViewController () @end @implementation UISwitchViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor blackColor]; [self createView:self.view]; } - (void)createView:(id)uiView{ UIView *view = (UIView *)uiView; UISwitch *switchView = [[UISwitch alloc] init]; switchView.frame = CGRectMake(20, 80, 300, 100); // switchView.backgroundColor = [UIColor redColor]; // 设置开启状态颜色 switchView.onTintColor = [UIColor orangeColor]; // 设置关闭颜色 switchView.tintColor = [UIColor yellowColor]; // 设置圆形按钮颜色 switchView.thumbTintColor = [UIColor purpleColor]; // 设置开启状态图片---(没效果) switchView.onImage = [UIImage imageNamed:@"tupian2.jpg"]; switchView.offImage = [UIImage imageNamed:@"tupian3.jpg"]; // 设置状态(这个地方的设置,是不会发送事件的,不回触发下面的事件。点击的时候才触发) [switchView setOn:true animated:true]; [switchView addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged]; [view addSubview:switchView]; } - (void)switchChange:(UISwitch *)mySwitch{ if (mySwitch.on) { NSLog(@"开关开启"); }else{ NSLog(@"开关关闭"); } } @end
相关文章推荐
- UISwitch 详解
- iOS开发——基本控件(UIButton,UILabel,UITextField,UISwitch,UISlider,UISegmentedControl)
- UISwitch用法-以及-自定义UISwitch控件
- IOS开发(2)之UISwitch开关控件
- iOS开发UISwitch开关控件属性介绍以及获取开关状态并做出响应
- iOS空间使用之UISwitch
- 自己写一个UISwitch
- UISwitch
- UISwitch打开,关闭按钮
- UISegmentedControl ,UIStepper,UISwitch,UISlider综合应用(实例需求)
- UISwitch的使用
- UI基础控件一
- ios 中滑块、开关、分段控件、操作表和警告的常用函数
- iOS 控件之 UISwitch
- iOS基础一 UISwitch
- iphone开发之自定义UIControl对象的视图 UISwitch的字体和颜色
- iPhone How-to:如何更改UISwitch的提示文本 推荐
- iOS UISwitch 用法总结
- IOS UISwitch 控件
- iOS UISwitch用法和示例