你的位置:首页 > 软件开发 > 操作系统 > UI常用控件

UI常用控件

发布时间:2015-04-14 20:00:20
//创建警告框对象UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"警告!" message:@"您确定退出吗?" delegate:self cancelButto ...

//创建警告框对象

UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"警告!" message:@"您确定退出吗?"  delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"继续",@"查看",nil];

//显示警告框

[alertView show];

 

//需要在.h里遵守UIAlertViewDelegate协议并且实现协议里面方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    //通过buttonIndex参数,可以区分点击的为哪个按钮

    NSLog(@"%i",buttonIndex);

}

(2)

//创建ActionSheet对象

UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"删除图片" otherButtonTitle:nil,nil];

//添加到self.view上

[actionSheet showInView:self.view];

//也需要在.h文件中遵守UIActionSheetDelegate协议实现协议里面的方法

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

    NSLog(@"%i",buttonIndex);

}

 (3)

//创建步进器对象

UIStepper *stp=[[UIStepper alloc]initWithFrame:CGRectMake(100,100,100,0)

[self.view addSubview:stp];

//设置步进器的最大值和最小值

stp.maximumValue=10;

stp.minimumValue=0;

//设置步进器的幅度 默认为一

stp.stepValue=2;

[stp addTarget:self action:@selector(stpClick:) forControlEvents:UIControlEventValueChanged];

//创建进度条对象

//进度不能设置最大和最小值

//进度条的取值范围0~1

UIProgressView *p=[[UIProgressView alloc]initWithFrame:CGRectMake(10,150,300,10)];

p.tag=200;

[self.view addSubview:p];

//p.progress设置进度条进度

 

(4)

NSArray *arr=@[@"菜单",@"购物车",@"结账",@"单价"];

UISegmentedCotrol *seg=[[UISegmentControl alloc]initWithItems:arr];

[self.view addSubview:seg];

seg.frame=CGRectMake(100,100,200,30);

//设置默认选中的位置

seg.selectedSegmentIndex=1;

//向segment控件中添加按钮

[seg insertSegmentWithTitle:@"数量" atIndex=1 animated:YES];

//给segment控件添加事件

[seg addTarget:self action:@selector(segChange:) forControlEvents:UIControlEventValueChanged];

-(void)segChange:(UISegmentedControl*)sg

{

    NSLog(@"%i",sg.selectedSegmentIndex);;

}

 (5)

UISlider *slider=[[UISlider alloc]initWithFrame:CGRectMake(10,200,300,30)];

[self.view addSubview:slider];

//设置划条最大值

slider.maximumValue=50;

//设置划条最小值

slider.minimunValue=0;

//给 划条添加滑动事件

[slider addTarget:self action:@selector(sliderChange:) forControlEvents:UIControlEventValueChanged];

//滑动结束后调用方法

slider.continuous=NO;

//设置左右两侧的滑条颜色

slider.minimumTrackTintColor=[UIColor redColor];

slider.maxmumTrackTintColor=[UIColor blueColor];

//设置滑条左右图片

slider.maximumValueImage=[UIImage imageNamed:@"b.png"];

slider.minimumValueImage=[UIImage imageNamed:@"a.png"];

-(void)sliderChange:(UISlider *)s

{

    NSLog(@"%f",s.value);

}

 

(6)

//创建开关控件对象

UISwitch *sw=[[UISwitch alloc]initWithFrame:CGRectMake(100,100,0,0);

[self.view addSubview:sw];

//设置开关处于开的状态

[sw setOn:YES];

[sw addTarget:self action:@selector(swChange:) forControlEvents:UIControlEventValueChanged];

 

//创建UIActivityIndicatorView对象,用于网络加载

UIActivityIndicatorView *act=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

act.frame=CGRectMake(100,150,100,100);

[self.view addSubview:act];

act.tag=100;

//开始加载

[act startAnimating];

 

 

-(void)swChange:(UISwitch*)sw

{

    

    UIActivityIndicatorView *act=(UIActivityIndicatorView *)[self.view viewWithTag:100];

  

    if (sw.isOn) {

        [act startAnimating];

        NSLog(@"on");

    }

    else

    {

        //停止加载

        [act stopAnimating];

        NSLog(@"off");

    }

    

    

}

 (7)

//创建网页加载控件对象

UIWebView *webView=[[UIWebView alloc]initWithFrame:CGRectMake(20,90,220,220)];

webView.backgroundColor=[UIColor redColor];

[self.view addSubview:webView];

webView.tag=200;

 

 

-(void)btnClick:(UIButton *)bt

{

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:UI常用控件

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录