IOS控件学习
2012-04-18 22:41
232 查看
0.
IBOutlet就是控件
IBAction相当于void
http://www.2cto.com/kf/201111/110593.html IOS开发笔记 (4) ---第一个IOS界面程序兼谈IB在XCode4.2中的应用
1.alert控件:点击button弹出alert。
2.Slider:移动slider,使label显示slider当前值。
3.textField输入:通过textField输入,按下button后显示在label。
4.点击背景隐藏软键盘:通过textField输入之后软键盘不会自己隐藏,需要自己编写,有2种方法。
2种方法触发的事件是一样的:
触发的方法不相同:
(1)在背景添加一个看不见的button,触发事件。
在viewDidLoad 中添加代码:
(2)背景UIView是不能触发事件的,所以把UIView的class改成UIControl,然后直接连接事件就可以了。
点击view图标
在这里修改class
http://www.techotopia.com/index.php/Writing_iOS_4_Code_to_Hide_the_iPhone_Keyboard Writing iOS 4 Code to Hide
the iPhone Keyboard
5. Segmented Control:按左边显示switch,按右边显示button
控件重叠时,显示的前后顺序在view中修改,列表最下面的显示在最前面。
/article/5935579.html IOS开发笔记(五)---基础控件的使用(Text
Filed ,Image View,Slider等)
6.Switch控制:移动一个switch,使另一个联动
7.创建tableView:
代码参考tableview创建代码实现,只要把viewDidLoad中创建tableview和数据源、委托的连接去掉就可以了。
数据源和委托连接通过IB实现,把tableView和File's Owner连接
IBOutlet就是控件
IBAction相当于void
http://www.2cto.com/kf/201111/110593.html IOS开发笔记 (4) ---第一个IOS界面程序兼谈IB在XCode4.2中的应用
1.alert控件:点击button弹出alert。
UIAlertView * alert1=[[UIAlertView alloc] initWithTitle:@"myView" message:@"hahah" delegate:self cancelButtonTitle:@"确定"otherButtonTitles:nil]; [alert1 addButtonWithTitle:@"确定2"]; [alert1 show]; //[alert1 release];
2.Slider:移动slider,使label显示slider当前值。
-(IBAction)showSlider1:(id)sender { label1.text=[NSString stringWithFormat:@"%.0f",slider1.value]; }
3.textField输入:通过textField输入,按下button后显示在label。
-(IBAction)showtext:(id)sender { label1.text=text1.text; }
4.点击背景隐藏软键盘:通过textField输入之后软键盘不会自己隐藏,需要自己编写,有2种方法。
2种方法触发的事件是一样的:
-(IBAction)hideSoftKeyboard:(id)sender { [text1 resignFirstResponder]; }
触发的方法不相同:
(1)在背景添加一个看不见的button,触发事件。
在viewDidLoad 中添加代码:
- (void)viewDidLoad { [super viewDidLoad]; backgroundButton=[[UIButton alloc] init];//创建button backgroundButton.frame=self.view.frame; [backgroundButton addTarget:self action:@selector(hideSoftKeyboard:) forControlEvents:UIControlEventTouchUpInside];//触发事件 [self.view addSubview:backgroundButton]; [self.view sendSubviewToBack:backgroundButton];//放在背景 }
(2)背景UIView是不能触发事件的,所以把UIView的class改成UIControl,然后直接连接事件就可以了。
点击view图标
在这里修改class
http://www.techotopia.com/index.php/Writing_iOS_4_Code_to_Hide_the_iPhone_Keyboard Writing iOS 4 Code to Hide
the iPhone Keyboard
5. Segmented Control:按左边显示switch,按右边显示button
控件重叠时,显示的前后顺序在view中修改,列表最下面的显示在最前面。
-(IBAction)segmentChange:(id)sender { UISegmentedControl *seg=(UISegmentedControl *)sender;//把sender转换成segment control if (seg.selectedSegmentIndex==0)//左边 { sw1.hidden=sw2.hidden=NO; buttonPress.hidden=YES; } else//右边 { sw1.hidden=sw2.hidden=YES; buttonPress.hidden=NO; } }
/article/5935579.html IOS开发笔记(五)---基础控件的使用(Text
Filed ,Image View,Slider等)
6.Switch控制:移动一个switch,使另一个联动
-(IBAction)switchChange:(id)sender { UISwitch * sw=(UISwitch *)sender; bool isOn=sw.isOn;//获取状态 [sw1 setOn:isOn animated:YES];//有动画效果 [sw2 setOn:isOn animated:YES]; }
7.创建tableView:
代码参考tableview创建代码实现,只要把viewDidLoad中创建tableview和数据源、委托的连接去掉就可以了。
数据源和委托连接通过IB实现,把tableView和File's Owner连接
相关文章推荐
- IOS控件学习之UIScrollView(3)
- 【iOS学习笔记】代码实现常用控件UIButton、UISlider、UISwitch、UISegmentedControl
- iOS学习之UIPickerView控件的简单使用
- 初入IOS之UI控件学习 UITableView
- iOS学习之UIDatePicker控件使用
- IOS学习之UIPickerView控件的简单使用
- IOS学习笔记(七)之UISegmentedControl分段控件的基本概念和使用方法
- ios控件学习 代码实现
- 蓝懿iOS培训日志8 控件学习2
- 黑马程序员——iOS 开发学习---循环结构及UI控件制作猜数字小游戏
- IOS学习5-UI控件
- IOS学习之基础控件简介
- iOS基础控件的学习
- iOS学习之UISwitch控件两种使用方法和监听
- iOS学习之UIPickerView控件的简单使用
- IOS控件学习:UILabel常用属性与用法
- ios 控件学习
- iOS学习之UIDatePicker控件使用
- iOS学习之UIPickerView控件的简单使用
- 学习iOS控件之UIImageView