OC UI控件之UILable UIBUtton UITextFiled

//--------------UILable-------------ide

    //建立一个标签字体

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

    //给标签设置内容spa

    lable.text = @"Hello World";3d

    

    //给标签内容设置颜色orm

    lable.textColor = [UIColor blackColor];事件

    

    //给标签设置字体图片

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

    

    //给标签设置背景颜色get

    //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];

相关文章
相关标签/搜索