UICommonlyUsedControls

【UI常用控件】

不需要学习多么深入,但是要知道系统提供的有用的控件。

一、UISwitch(开关)

二、UIActivityIndicatorView(活动指示视图)

三、UISlider(滑动条)

四、UIProgressView(进度条)

五、UIStepper(步进器)

六、UISegmentedControl(分段控制)

七、UIActionSheet(操作表单)

八、UIAlertView(警告视图)  [alertView show]

九、UITextView(文本视图)

一、UISwitch(开关)

#pragma mark - 开关

- (void)createUISwitch {

UISwitch *sw = [[UISwitch alloc]init];

//开关的宽高没有影响

sw.frame = CGRectMake(10, 100, 0, 0);

//用形变transform 可以修改大小

sw.transform = CGAffineTransformMakeScale(1.5, 1.5);

[self.view addSubview:sw];

//添加事件

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

//设置边框颜色

sw.tintColor = [UIColor blueColor];

//设置打开的颜色

sw.onTintColor = [UIColor purpleColor];

//设置小球的颜色

sw.thumbTintColor = [UIColor greenColor];

}

- (void)switchChange:(UISwitch*)sw {

if (sw.on == YES) {

NSLog(@"开着");

}

else{

NSLog(@"关闭");

}

}

二、UIActivityIndicatorView(活动指示视图)

//状态栏上边的网络加载指示器

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

- (void)createView {

//    UIActivityIndicatorViewStyleWhiteLarge,大白块

//    UIActivityIndicatorViewStyleWhite,白色

//    UIActivityIndicatorViewStyleGray,灰色

UIActivityIndicatorView *avi = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

avi.frame = CGRectMake(0, 0, 50, 50);

avi.center = self.view.center;

avi.tag = 100;

[self.view addSubview:avi];

[avi startAnimating];

}

//触摸屏幕时让指示器停止

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

[super touchesBegan:touches withEvent:event];

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

[avi stopAnimating];

//关闭状态栏上边的网络加载指示器

[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

}

三、UISlider(滑动条)

- (void)createView {

UISlider *sl = [[UISlider alloc]init];

//高度不生效

sl.frame = CGRectMake(100, 100, 300, 100);

[self.view addSubview:sl];

//设置颜色

//运行过的滑动条的颜色

sl.minimumTrackTintColor = [UIColor greenColor];

//刚开始滑动条的颜色

sl.maximumTrackTintColor = [UIColor redColor];

//球球的颜色

sl.thumbTintColor = [UIColor purpleColor];

//设置值

//球球在滑动条上的位置,不设置默认0;

sl.minimumValue = 0.3;

sl.maximumValue = 1.0;

//初始值  球球在滑动条上的初始位置

sl.value = 0.3;

[sl addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];

//是否持续调用事件  默认YES,在滑动的过程中一直改变值 ,NO只有在滑动停止的时候才改变值

sl.continuous = NO;

}

- (void)changeValue:(UISlider*)sender{

NSLog(@"%2f",sender.Value);

}

四、UIProgressView(进度条)

- (void)createView {

//    UIProgressViewStyleDefault,     // normal progress bar

//    UIProgressViewStyleBar,

UIProgressView *pv = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];

//高度无效

pv.frame = CGRectMake(20, 100, 300, 100);

[self.view addSubview:pv];

//设置进度条颜色

pv.trackTintColor = [UIColor greenColor];

//进度条走过的颜色

pv.progressTintColor = [UIColor redColor];

//进度

pv.progress = 0.1;

[self autoChange:pv];

// [pv setProgress:0.8 animated:YES];

}

//自动增加

- (void)autoChange:(UIProgressView*)pv {

CGFloat progress = pv.progress;

progress +=0.001;

[pv setProgress:progress animated:YES];

if (progress >= 1.0) {

return;

}

//延迟调用一个方法

[self performSelector:@selector(autoChange:) withObject:pv afterDelay:0.01];

}

五、UIStepper(步进器)

//步进器

- (void)createView {

UIStepper *sp = [[UIStepper alloc]init];

//宽高无效

sp.frame = CGRectMake(20, 100, 200, 100);

[self.view addSubview:sp];

//添加事件

[sp addTarget:self action:@selector(stepperChange:) forControlEvents:UIControlEventValueChanged];

//设置值

sp.minimumValue = 5;

sp.maximumValue = 100;

//一次加多少

sp.stepValue = 5;

sp.tintColor = [UIColor yellowColor];

//设置跨越边界,默认不能跨越

sp.wraps = NO;

//长按是否持续加减

sp.autorepeat = NO;

//是否持续调用事件

sp.continuous = NO;

}

- (void)stepperChange:(UIStepper*)sp {

NSLog(@"%.2f",sp.value);

}

六、UISegmentedControl(分段控制)

- (void)createView {

NSArray *items = @[@"好友",@"消息",@"动态"];

UISegmentedControl *sc = [[UISegmentedControl alloc]initWithItems:items];

sc.frame = CGRectMake(100, 100, 200, 50);

[self.view addSubview:sc];

//设置颜色

sc.backgroundColor = [UIColor greenColor];

sc.tintColor = [UIColor redColor];

//设置字体大小和颜色(对应状态)

NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor blueColor],NSForegroundColorAttributeName,[UIFont systemFontOfSize:20],NSFontAttributeName, nil];

[sc setTitleTextAttributes:dic forState:UIControlStateSelected];

//添加事件

[sc addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];

}

- (void)changeValue:(UISegmentedControl*)sender {

NSLog(@"%ld",sender.selectedSegmentIndex);

//事件分发

}

七、UIActionSheet(操作表单)

/**

*  ios8以后 新的actionSheet 和alertView 和在一起

*/

- (void)createAlertViewController {

//    UIAlertControllerStyleActionSheet = 0,

//    UIAlertControllerStyleAlert

UIAlertController *alc= [UIAlertController alertControllerWithTitle:@"标题" message:@"信息" preferredStyle:UIAlertControllerStyleActionSheet];

//添加按钮

//    UIAlertActionStyleDefault = 0,

//    UIAlertActionStyleCancel,

//    UIAlertActionStyleDestructive

//没有设置代理,用block替换了代理

UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

NSLog(@"确定按钮点击");

}];

UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

}];

UIAlertAction *desc = [UIAlertAction actionWithTitle:@"其他" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

}];

//添加进去

[alc addAction:action];

[alc addAction:cancel];

[alc addAction:desc];

[self presentViewController:alc animated:YES completion:nil];

}

- (void)createView {

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"title" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"desc" otherButtonTitles:@"其他1",@"其他2", nil];

actionSheet.tag = 100;

//显示

[actionSheet showInView:self.view];

}

//点击了哪个Button

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

NSLog(@"%ld",buttonIndex);

//这里边做事件分发

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

[super touchesBegan:touches withEvent:event];

//    UIActionSheet *ac = (id)[self.view viewWithTag:100];

//    [ac showInView:self.view];

[self createView];

}

八、UIAlertView(警告视图)

@interface ViewController7 ()<UIAlertViewDelegate>

@end

- (void)createView {

UIAlertView *al = [[UIAlertView alloc]initWithTitle:@"标题" message:@"你好" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"更新", nil];

//显示

[al show];

}

//点击按钮的代理

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

NSLog(@"%ld",buttonIndex);

if (alertView.tag == 100) {

UIAlertView *al1 = [[UIAlertView alloc]initWithTitle:@"另一个alert" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

al1.tag = 101;

//        UIAlertViewStyleDefault = 0,

//        UIAlertViewStyleSecureTextInput,安全输入

//        UIAlertViewStylePlainTextInput,普通输入

//        UIAlertViewStyleLoginAndPasswordInput 两个输入框

al1.alertViewStyle = UIAlertViewStylePlainTextInput;

UITextField *textf = [al1 textFieldAtIndex:0];

textf.placeholder = @"请输入用户名";

[al1 show];

}

else {

NSLog(@"点了另一个alertView");

UITextField *textfeild = [alertView textFieldAtIndex:0];

NSLog(@"输入了%@",textfeild.text);

}

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

[super touchesBegan:touches withEvent:event];

[self createView];

}

九、UITextView(文本视图)

- (void)createTextView {

UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(20, 100, 100, 300)];

[self.view addSubview:textView];

//取消导航对布局的影响

self.edgesForExtendedLayout = UIRectEdgeNone;

//

textView.backgroundColor = [UIColor orangeColor];

textView.textColor = [UIColor purpleColor];

textView.font = [UIFont systemFontOfSize:30];

//取消滑动

textView.scrollEnabled = NO;

//    textView.text = @"jdfjdjglsdfjgjdfsljgsldfjhklsjglkjfdlkjhmlksfjhkllljmfdotjrkjhodkrtoghtrgkhotrkgodrtkgkdtrkgdotkrgoktrgokrtgtrh";

//    //设置不可编辑(必须text里边有内容)

//    textView.editable = NO;

//代理方法 设置代理

textView.delegate = self;

}

//实现代理方法

//是否允许开始编辑

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {

NSLog(@"开始编辑");

return YES;

}

- (BOOL)textViewShouldEndEditing:(UITextView *)textView {

NSLog(@"结束编辑");

return YES;

}

- (void)textViewDidBeginEditing:(UITextView *)textView {

NSLog(@"已经开始编辑");

}

- (void)textViewDidChange:(UITextView *)textView {

NSLog(@"已经改变");

}

- (void)textViewDidChangeSelection:(UITextView *)textView {

NSLog(@"只要选中内容就会调用");

}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

//只要输入内容就会调用

NSLog(@"%@",text);

return YES;

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

[super touchesBegan:touches withEvent:event];

//直接找到textView 取消第一响应

//self.view endEditing

[self.view endEditing:YES];

}

UI常用控件的更多相关文章

  1. UI常用控件的一些属性

    UILable 1 //设置文本信息 2 nameLable.text = @"用户名:"; 3 //对齐方式(居中 居左 局右); 4 nameLable.textAlignme ...

  2. easy ui 常用控件配置

    table comboBox 下拉高度 panelHeight:'auto' textBox

  3. [WinForm]WinForm跨线程UI操作常用控件类大全

    前言 在C#开发的WinForm窗体程序开发的时候,经常会使用多线程处理一些比较耗时之类的操作.不过会有一个问题:就是涉及到跨线程操作UI元素. 相信才开始接触的人一定会遇上这个问题. 为了解决这个问 ...

  4. 【Android Studio】安卓开发初体验3.1——UI设计之常用控件

    常用控件 首先对xml文件的编辑有三种模式 Code为纯代码 Split是一边代码,一边预览效果图 Designer就是有UI设计界面 TextView 用于在界面上显示一段文本信息 所有控件都可以在 ...

  5. Day3 UI:7种常用控件、4种基本布局

    Android常用控件 TextView <TextView android:id="@+id/text_view" android:layout_width="m ...

  6. UWP学习记录7-设计和UI之控件和模式4

    UWP学习记录7-设计和UI之控件和模式4 1.翻转视图 使用翻转视图浏览集合中的图像或其他项目(例如相册中的照片或产品详细信息页中的项目),一次显示一个项目. 对于触摸设备,轻扫某个项将在整个集合中 ...

  7. Xamarin Studio在Mac环境下的配置和Xamarin.iOS常用控件的示例

    看过好多帖子都是Win环境装XS,Mac只是个模拟器,讲解在Mac环境下如何配置Xamarin Studio很少,也是一点点找资料,东拼西凑才把Xamarin Studio装在Mac上跑起来,如下: ...

  8. B/S一些小知识及常用控件

    一: B/S网页的运行 页面在设计的时候,本身就是一个类.在运行的时间,是一个对象. 其中aspx和aspx.cs是在同一个类下. aspx是主要是负责界面,而aspx.cs主要是负责数据逻辑. 呈现 ...

  9. QMUI UI库 控件 弹窗 列表 工具类 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

随机推荐

  1. hdu_5794_A Simple Chess(lucas+dp)

    题目链接:hdu_5794_A Simple Chess 题意: 给你n,m,从(1,1)到(n,m),每次只能从左上到右下走日字路线,有k(<=100)的不能走的位置,问你有多少方案 题解: ...

  2. cmstop传递什么控制器和方法---就实例化该控制器

    object顶级类class object 第一级抽象类controllerabstract class controller extends object 第二级抽象类controller_abst ...

  3. 认识ASP.NET MVC的5种AuthorizationFilter

    在总体介绍了筛选器及其提供机制(<深入探讨ASP.NET MVC的筛选器>)之后,我们按照执行的先后顺序对四种不同的筛选器进行单独介绍,首先来介绍最先执行的AuthorizationFil ...

  4. how computer boot up?

    The power button activates the power supply in the PC, sending power to the motherboard and other co ...

  5. @font-face的用法

    几乎所有浏览器(包括最古老的IE6)也支持的网络字体@font-face的用法是: @font-face { font-family: 'MyWebFont'; src: url('webfont.e ...

  6. TCP/IP,http,socket,长连接,短连接——小结。

    来源:http://blog.chinaunix.net/uid-9622484-id-3392992.html TCP/IP是什么? TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层. ...

  7. LVS负载均衡的三种模式和八种算法总结

    三种LVS负载均衡模式 调度器的实现技术中,IP负载均衡技术是效率最高的,IP虚拟服务器软件(IPVS)是在linux内核中实现的。 LVS负载均衡模式---1.NAT模式 NAT用法本来是因为网络I ...

  8. Jquery.Linq用法

    下载:http://linqjs.codeplex.com/ LINQ Pad Enumerable.Range(0, 20).Where("$ % 3 == 0").Select ...

  9. PHP上传文件详解

    1.上传文件使用的提交方式和请求Content-type POST提交方式,原始的form表单提交请加上enctype="multipart/form-data" 2.MAX_FI ...

  10. KVM 基本硬件容量扩容

    在工作当中如果虚拟机的容量不够使用 如何添加呢? CPU添加 cpu添加有两种方式: 1 创建虚拟机的时候可以添加 # virt-install --help | grep cpu --vcpus=V ...