zoukankan      html  css  js  c++  java
  • iOS笔记之UIKit_UIButton

       //UIButton的基本属性

        _btn = [UIButton buttonWithType:UIButtonTypeCustom];

        _btn.frame = CGRectMake(0, 200, 90, 90);

        _btn.backgroundColor = [UIColor redColor];

        _btn.tag = 100;

        [_btn setTitle:@"我爱你" forState:UIControlStateNormal ];

        [_btn setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal ];

        [_btn addTarget:self action:@selector(btnClick:) forControlEvents: UIControlEventTouchUpInside];

        //设置button的圆角、边框

        _btn.layer.cornerRadius  =10;

        _btn.layer.borderWidth = 5.0;

        _btn.layer.borderColor = [UIColor blueColor].CGColor;

       //设置button标签文字的颜色 

        [_btn setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];

       //标签文字的字体

        [_btn.titleLabel setFont:[UIFont systemFontOfSize:28]];

        _btn.tag = 101;

        

        [self.view addSubview:_btn];

        

        

        UIButton*bnt = [UIButton buttonWithType:UIButtonTypeSystem];

        bnt.frame = CGRectMake(60, 300, 80, 80);

        //button的颜色    

        bnt.backgroundColor = [UIColor grayColor];

        bnt.layer.cornerRadius = 40;

        

        bnt.layer.borderColor = [UIColor redColor].CGColor;

        bnt.layer.borderWidth  = 5.0;

        [bnt setTitle:@"mapanguan" forState:UIControlStateNormal ];

        

        [bnt setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal ];

        

        [bnt.titleLabel setFont:[UIFont systemFontOfSize:20]];

        

        bnt.tag = 102;

         //添加点击事件  

         [bnt addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchDragOutside];

        

        

        [self.view addSubview:bnt];

        

        

    }

    -(void)btnClick:(UIButton*)btn{

        if (101 == _btn.tag) {

            NSLog(@"按钮被点击了");

         //点击显示随机颜色(需先定义)

            int index = arc4random()%[self.colors count];

            self.btn.backgroundColor = self.colors[index];

        }

    }

  • 相关阅读:
    01_javaSE面试题:自增变量
    SpringBoot(二十)_404返回统一异常处理结果
    MD5加密工具代码
    SpringBoot(十九)_spring.profiles.active=@profiles.active@ 的使用
    读取本地文件转化成MultipartFile
    remote: http basic: access denied fatal: authentication failed for '‘解决办法
    git报错_you are not allowed to push code to protected branches on this project
    SpringBoot(十八)_springboot打成war包部署
    sql优化问题笔记(mysql)
    gitbook 简单使用
  • 原文地址:https://www.cnblogs.com/mapanguan/p/4149359.html
Copyright © 2011-2022 走看看