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

        }

    }

  • 相关阅读:
    到底什么是 ROI Pooling Layer ???
    Interacted Action-Driven Visual Tracking Algorithm
    论文笔记:Multi-Agent Actor-Critic for Mixed Cooperative-Competitive Environments
    论文笔记: Dual Deep Network for Visual Tracking
    (zhuan) Attention in Neural Networks and How to Use It
    深度学习课程笔记(六)Error
    华尔街
    使用makefile
    财商入门 --- 富爸爸,穷爸爸
    分形之拆分三角形(Split Triangle)
  • 原文地址:https://www.cnblogs.com/mapanguan/p/4149359.html
Copyright © 2011-2022 走看看