iOS开发中几个有意思的小控件

来源:互联网 发布:西装面料品牌 知乎 编辑:程序博客网 时间:2024/04/23 20:39

大家好,今天为大家分享一些iOS开发的几个有意思的小控件
在iOS开发的过程中,会遇到很多的方法,我们应该学会多运用这些方法
下面为大家讲解几个小控件 
 

左右选择框


//定义一个UIsegmentedControl的控件,添加字体


    UISegmentedControl *seg = [[UISegmentedControl alloc]

 initWithItems:@[@"ddd",@"ddd"]];

//设置坐标和大小


    [seg setFrame:CGRectMake(50, 100, 100, 30)];


//添加视图


    [_window addSubview:seg];



//旋转按钮


定义一个UIActivitylndicatorView,并设置坐标


    UIActivityIndicatorView *alert  = [[UIActivityIndicatorView

 alloc]initWithFrame:CGRectMake(50, 50, 50, 50)];


//设置背景颜色


    [alert setColor:[UIColor redColor]];


//添加视图


    [_window addSubview:alert];


//开启动画


    [alert startAnimating];



    //下弹选择框


在这个选择框中,可以看到标题和很多的选项,initWithTitle是设置标题


的,delegate是设置控件使用协议的代理人,我们设置为自己,canceButtonTitle


是设置弹出菜单的最下面的取消行,destructiveButton是设置红色字体的横


向栏,只有这个标题栏是居顶端并且是红色的,otherButtonTitle是设置其它横


向栏,可以无限添加.

//    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"标题"

 delegate:self cancelButtonTitle:@"取消"

 destructiveButtonTitle:@"buttonq"

 otherButtonTitles:@"button2",@"ddddd", nil];


//添加视图


//    [sheet showInView:_window];


//    //滑动选择框,移动蜂窝数据的那个按钮就是我们所说的UISwith,定义

并设置大小

//    

UISwitch *sw = [[UISwitch alloc] initWithFrame:CGRectMake(50, 150, 50, 30)];

////    

[sw setBackgroundColor:[UIColor redColor]];

//   

 [_window addSubview:sw];

    

//工具条


设置工具条,此控件就是照相机最上边那条黑边


    UIToolbar *tool = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 528,

 320, 40)];


//设置背景颜色


   [tool setBackgroundColor:[UIColor blueColor]];


   [_window addSubview:tool];


这几个控件有很多应用的地方,我们可以灵活运用.



0 0