• ios UIKit 基础控件创建与属性


    创建UIlabel标签,设置属性。

    #pragma mark--UILabel

        //1.创建控件

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

        //2.设置大小

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

        //3.设置背景颜色

        label.backgroundColor = [UIColor yellowColor];

        //4.设置文本

        label.text = @"hello world";

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



    模拟器运行效果图:



  • 相关阅读:
    AOP 相关包
    Dubbo学习(一) Dubbo原理浅析
    maven 三个仓库表
    关于servlet中doGet和doPost乱码再一次理解
    关于对String中intern方法的理解
    模拟文件上传(五):为文件添加描述信息
    模拟文件上传(四):对于前面三版中一些出错细节进行处理
    对于模拟文件上传(三)中,批量上传,传空值抛异常前台约束实现
    模拟文件上传(三):使用apache fileupload组件进行文件批量上传
    模拟文件上传(二):使用apache fileupload组件进行文件上传
  • 原文地址:https://www.cnblogs.com/Jia-Heng-He465/p/6480870.html
Copyright © 2020-2023  润新知