UI常用控件_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > UI常用控件

UI常用控件

 2015/4/14 21:28:45  jsonUserList  程序员俱乐部  我要评论(0)
  • 摘要://创建警告框对象UIAlertView*alertView=[[UIAlertViewalloc]initWithTitle:@"警告!"message:@"您确定退出吗?"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",@"继续",@"查看",nil];//显示警告框[alertViewshow];//需要在.h里遵守UIAlertViewDelegate协议并且实现协议里面方法-(void)alertView:
  • 标签:常用 控件

//创建警告框对象

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

{
//获得文本框对象

UITextField *textField=(UITextField *)[self.view viewWithTag:100];

//获得文本框中的网址

NSString *strURL=textField.text;

//获得webView对象

UIWebView *webView=(UIWebView *)[self.view viewWithTag:200];

NSURL *url=[NSURL URLWithString:strURL];

//封装网络请求类

NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url];

//加载网络请求

[webView loadRequest:request];

}

 

发表评论
用户名: 匿名