OC UI控件之UILable UIBUtton UITextFiled

//--------------UILable-------------

    //创建一个标签

    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(80, 40, 200,50)];

    //给标签设置内容

    lable.text = @"Hello World";

    

    //给标签内容设置颜色

    lable.textColor = [UIColor blackColor];

    

    //给标签设置字体

    lable.font = [UIFont fontWithName:@"Arial" size:20];

    

    //给标签设置背景颜色

    //lable.backgroundColor = [UIColor greenColor];

    lable.backgroundColor = [UIColor colorWithRed:0.5 green:0.8 blue:0.5 alpha:0.5];

    

    //给标签设置边框宽度

    lable.layer.borderWidth = 10;

    

    //给标签设置边框颜色

    //lable.layer.borderColor = [UIColor orangeColor].CGColor;

    lable.layer.borderColor = [UIColor colorWithWhite:0.1 alpha:0.3].CGColor;

    

    //字体居中

    lable.textAlignment = NSTextAlignmentCenter;

    

    //设置字体:粗体,正常的是SystemFontOfSize

    lable.layer.cornerRadius = 20;

    

    //设置阴影

    lable.layer.shadowColor=[UIColor blackColor].CGColor;

    lable.layer.shadowOffset=CGSizeMake(10, 20);//阴影大小

    lable.layer.shadowRadius=20;

    

    //设置lable 的行数

    lable.numberOfLines = 2;

    

    //设置lable中文字是否可变,默认为YES

    lable.enabled = NO;

    

    //设置高亮

    lable.highlighted = YES;

    lable.highlightedTextColor = [UIColor orangeColor];


    //把标签添加到视图

    [self.view addSubview:lable];

    

    

    

    //--------------UITextFiled-------------

    //设置一个文本框

    UITextField *textFiled = [[UITextField alloc]initWithFrame:CGRectMake(80,100, 200, 50)];

    

    //设置输入框边框样式

    textFiled.borderStyle=UITextBorderStyleLine;

    

    //设置输入框的加密显示

    textFiled.secureTextEntry=YES;

    

    //设置输入框的字体居中位置

    textFiled.textAlignment=NSTextAlignmentCenter;

    

    //当输入框没有内容时,水印提示placeholder 提示内容为password

    textFiled.placeholder=@"提示";

    

    //给文本框添加背景颜色

    textFiled.backgroundColor = [UIColor colorWithRed:0.6 green:0 blue:0 alpha:0.2];

    

    //将文本框添加到视图中

    [self.view addSubview:textFiled];

    

    

    

    

     //--------------UIButton-------------

    //设置一个button

    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(80, 200, 50, 50)];

    

    //设置button内容

    [button setTitle:@"click" forState:UIControlStateNormal];

    

    //设置内容颜色

    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];

    //设置button背景颜色

    button.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0 alpha:0.4];

    

    //设置按钮背景图片

    //    [button setBackgroundImage:[UIImage imageNamed:@"0"] forState:UIControlStateNormal];

    

    //设置按钮边框

    [button.layer setCornerRadius:10.0]; //设置矩形四个圆角半径

    [button.layer setBorderWidth:1.0]; //边框宽度

    [button.layer setBorderColor:[UIColor blueColor].CGColor];//边框颜色

    

    //button添加点击事件

    [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

    

    //button移除点击事件

//    [button removeTarget:self action:@selector(<#selector#>) forControlEvents:<#(UIControlEvents)#>]

    

    //button添加到视图中

    [self.view addSubview:button];


转载于:https://my.oschina.net/u/2483162/blog/530091

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值