phoenix13

导航

 

0.

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;

}
}

 

 http://www.cnblogs.com/ternastone/archive/2011/11/08/2241863.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连接

posted on 2012-02-01 17:25  phoenix13  阅读(1480)  评论(0编辑  收藏  举报