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

        }

    }

  • 相关阅读:
    Python基于正则表达式实现文件内容替换的方法
    python数据处理实战
    python数据处理实战
    Python命令行参数解析模块getopt使用实例
    Python命令行参数解析模块getopt使用实例
    python命令行参数解析OptionParser类用法实例
    vim中权限不足时不用退出而强制保存
    C++11 STL算法简介
    每天一个linux命令(6) ar命令
    mysql++ Query
  • 原文地址:https://www.cnblogs.com/mapanguan/p/4149359.html
Copyright © 2011-2022 走看看