ios 中滑块、开关、分段控件、操作表和警告的常用函数

来源:互联网 发布:买了东西能寄农村淘宝 编辑:程序博客网 时间:2024/04/30 06:59

对于SLider通过value属性可以得到当前滑块的值

 UISlider *slider=(UISlider*)sender;
    self.sliderLabel.text=[[[NSString alloc] initWithFormat:@"%f",slider.value] autorelease];

对于UISwithch 控件,on属性可以判断出当前值,通过setOn函数设置当前滑块的状态

 UISwitch *whichSwitch=(UISwitch *)sender;
    BOOL setting=whichSwitch.on;
    [self.leftSwitch setOn:setting animated:NO];
    [self.rightSwitch setOn:setting animated:YES];

对于分段控件,属性selectedSegmentIndex可得到当前选择的分段

UISegmentedControl *segmentControl=(UISegmentedControl *)sender;
    NSInteger segment=segmentControl.selectedSegmentIndex;

操作表常用函数

 UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:@"are you sure?" delegate:self cancelButtonTitle:@"no way" destructiveButtonTitle:@"yes,i'm sure" otherButtonTitles:nil];

第一个参数是标题,第二个参数表示操作表的委托,如果是nil,则不做任何特殊处理,如果是self,则会调用本地-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 函数,接下来是取消按钮的标题,nil是结束符

警告的常用语句
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"title" message:msg delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil];
        [alert show];

控件状态
 每个iphone 有四种不同的控件状态,并且任何时侯只能处于其中一种,普通状态是默认状态,highlight状态是值该控件正在被使用的状态,禁用状态是值控件被关闭时的状态,选中状态用于只是该控件被选中。




原创粉丝点击