ios UIKit 基础控件建立与属性

建立UIlabel标签,设置属性。ide

#pragma mark--UILabel函数

    //1.建立控件字体

    UILabel *label = [[UILabel alloc] init];spa

    //2.设置大小orm

    label.frame = CGRectMake(50, 100, 300, 40);事件

    //3.设置背景颜色ip

    label.backgroundColor = [UIColor yellowColor];get

    //4.设置文本it

    label.text = @"hello world";io

    //5.设置文本居中

    label.textAlignment = NSTextAlignmentCenter;

    //6.设置字体颜色

    label.textColor = [UIColor darkGrayColor];

    //设置圆角

//    label.layer.cornerRadius = 8;

    //7.添加到控制器视图上

    [self.view addSubview:label];


模拟器运行效果图:



textField建立与属性设置:

//建立与位置设定

 UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 200, 300, 44)];

    //2.文本框样式  必须设置(边框)

//    textField.borderStyle = UITextBorderStyleBezel;

    //3.提示语句

    textField.placeholder = @"请输入我很是帅";

    //4.设置文本框背景颜色

    textField.backgroundColor = [UIColor whiteColor];

    //设置文本框圆角

    textField.layer.cornerRadius = 8;

    //添加到视图

    [self.view  addSubview:textField];


模拟器运行效果图:



#pragma mark -- UIButton

    //1.建立按钮方法,使用便利构造

    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeSystem];

    //2.设置按钮位置与大小

    sureBtn.frame = CGRectMake(150, 300, 100, 40);

    //3.设置按钮颜色

    sureBtn.backgroundColor = [UIColor redColor];

    //4.正常状态下的标题显示

    [sureBtn setTitle:@"登陆" forState:UIControlStateNormal];

    //5.设置按钮文本的文本颜色

    [sureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

//    //6.设置选中下的状态与文本颜色

//    [sureBtn setTitle:@"取消" forState:UIControlStateSelected];

//    [sureBtn setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];

    

    //1.设置圆角的半径

    sureBtn.layer.cornerRadius = 8;

//    sureBtn.layer.masksToBounds = YES;

    sureBtn.clipsToBounds = YES;

    //为sureBtn添加点击事件    (sureButtonPressed:)是点击后执行的函数

    [sureBtn addTarget:self action:@selector(sureButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

    //添加到视图

    [self.view addSubview:sureBtn];



模拟器运行效果图:

相关文章
相关标签/搜索