UI常用控件集合

1、UILabel属性
a) 创建方法:UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(200, 0, 100, 25)];

b) 属性:textColor           // 文本颜色
text                   // 文本值
font                   // 文本字体

textAlignment   // 文本对齐

numberOfLines // 文本行数

2、UITextField
a) 创建方法:UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(200, 0, 100, 25)];

b) autocapitalizationType             // 自动大写类型,可禁止
keyboardType                       // 键盘类型
borderStyle                        // 输入框显示样式
returnKeyType                      // 键盘上的return键的显示样式
clearButtonMode                    // 清除按钮模式
placeholder                        // 输入框为空显示的提示文字
secureTextEntry                    // 是否提供文本隐藏特性(密码输入框)
textAlignment                      // 输入框中的文本对齐方式
textColor                          // 输入框中的文本颜色
font                               // 输入框的文本字体
text                               // 输入框中的文本


c) 注意代理方法 ------> 引入代理协议

3、UIImageView
1) 创建方法
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
imageView.image = [UIImage imageNamed:@"image.png"];

                       // 用户交互
imageView.userInteractionEnabled = YES;


2) 属性
size                                      // 图片的大小 (只读)
scale                                     // 缩放倍数    (只读)
images                                    // 获取图片对象数组

4、UIButton
1)  创建方法
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

2) 方法
button.frame = CGRectMake(0, 40, 100, 30);
//设置平常状态下按钮的标题
[button setTitle:@"按钮" forState:UIControlStateNormal];
//设置高亮状态下按钮的标题
[button setTitle:@"按钮按下" forState:UIControlStateHighlighted];    
//设置点击事件响应的方法
[button addTarget:self action:@selector(buttonAction) 
            forControlEvents:UIControlEventTouchUpInside];

5、弹窗

    // 创建alertView

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"标题"

                                                    message:@"提示信息"

                                                   delegate:self

                                          cancelButtonTitle:@"取消"

                                          otherButtonTitles:@"确定", nil];

注:UIAlertView虽然可以实现弹窗,但iOS 9不推荐使用

使用UIAlertController来实现弹窗:

1. 创建一个UIAlertController   

       UIAlertControllerStyleActionSheet       下拉弹窗

UIAlertControllerStyleAlert             中间弹窗

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示信息"

                                                                   message:@"你确定要学删除吗?"

                                                            preferredStyle:UIAlertControllerStyleAlert];

2. 创建cancel

         UIAlertActionStyleDefault,         确定按钮

         UIAlertActionStyleCancel,          取消按钮

         UIAlertActionStyleDestructive      加粗按钮 

    // 创建取消键

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"

                                                           style:UIAlertActionStyleCancel

                                                         handler:^(UIAlertAction * _Nonnull action) {

                                                             NSLog(@"取消");

                                                         }];

    

    // 创建ok

    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定"

                                                       style:UIAlertActionStyleDefault

                                                     handler:^(UIAlertAction * _Nonnull action) {

                                                         NSLog(@"确定按钮");

                                                     }];

6、滑块
1) 创建方法
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 0, 150, 25)];
2) 事件响应
[slider addTarget:self action:@selector(sliderAction:) 
         forControlEvents:UIControlEventValueChanged];

7、UISegmentedControl分段控件
    1) 创建方法
    // 设置按钮的标题数组
NSArray *btnarray = [NSArray arrayWithObjects:@"选择",@"搜索",@"邮箱", nil];
// 创建分段控件
UISegmentedControl *segmentCtrl = [[UISegmentedControl alloc] initWithItems:array];
segmentCtrl.frame = CGRectMake(20, 0, 150, 25);


2) 响应事件
[segmentCtrl addTarget:self action:@selector(segmentAction:)                 forControlEvents:UIControlEventValueChanged];

8、UIActivityIndicatorView 活动指示器(风火轮)

 // 创建一个指示器

 UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc]            initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

 // 设置frame

    activityView.frame = CGRectMake(20, 100, 50, 50);

 // 设置背景颜色

    activityView.backgroundColor = [UIColor orangeColor];    

 // 设置tag

    activityView.tag = 1001;

 // 加载动画

   [activityView startAnimating];








    




     






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值