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

}

}

iOS笔记之UIKit_UIButton的更多相关文章

  1. 荼菜的iOS笔记--UIView的几个Block动画

    前言:我的第一篇文章荼菜的iOS笔记–Core Animation 核心动画算是比较详细讲了核心动画的用法,但是如你上篇看到的,有时我们只是想实现一些很小的动画,这时再用coreAnimation就会 ...

  2. IOS笔记 1

    < ![CDATA[ 笔记 UIWindows 与UIView的关系iOS的坐标系统视图层次结构视图坐标(Frame和Bounds区别)UIView的常用属性和方法坐标系统的变换UIView内容 ...

  3. 【转】iOS笔记-自定义控件(OC)

    原文网址:http://www.jianshu.com/p/f23862eb7b8a 导读: iOS开发中,很多时候系统提供的控件并不能很好的满足我们的需求,因此,自定义控件便成为搭建UI界面中必不可 ...

  4. iOS笔记———数据存储

    应用沙盒:应用文件系统的根目录,每个应用都有独自的沙盒相互:在xcode中可以用NSHomeDirectory()函数,打印当前应用的沙盒根路径. 应用程序包:包含了所有资源文件和执行文件; * Do ...

  5. Xamarin开发IOS笔记:切换输入法时输入框被遮住

    在进行IOS开发的过程中,出现类似微信朋友圈的交互界面,当用户遇到感兴趣的内容可以进行评论.为了方便评论输入,当出现评论输入框的时候自动将评论输入框移动至键盘的上方,这样方便边输入边查看. 当用户隐藏 ...

  6. 【IOS笔记】Delegation

    Delegation Delegation is a simple and powerful pattern in which one object in a program acts on beha ...

  7. 【IOS笔记】Event Delivery: The Responder Chain

    Event Delivery: The Responder Chain  事件分发--响应链 When you design your app, it’s likely that you want t ...

  8. 【IOS笔记】Gesture Recognizers

    Gesture Recognizers Gesture recognizers convert low-level event handling code into higher-level acti ...

  9. 【IOS笔记】About Events in iOS

    About Events in iOS Users manipulate their iOS devices in a number of ways, such as touching the scr ...

随机推荐

  1. .NET发送邮件的方法

    整理一下,在.NET中发送邮件的一个方法,代码如下: public static string Net_Email(string strSendto, string strCC, string str ...

  2. Activiti任务认领

    Activiti任务认领 TaskService taskService; taskService.setAssignee(String taskId, String userId);taskServ ...

  3. MVVM Light 笔记

    4.关于子视图, MVVMLight Using Two Views:http://www.codeproject.com/Articles/323187/MVVMLight-Using-Two-Vi ...

  4. TCP与UDP传输协议

    目录结构: contents structure [-] 1 TCP协议和UDP协议的比较 1.1 TCP协议 TCP的全称是Transmission Control Protocol (传输控制协议 ...

  5. 【技术课堂】如何管理MongoDB数据库?

  6. 基础知识之nginx重写规则

    nginx重写规则 nginx rewrite 正则表达式匹配 大小写匹配 ~ 为区分大小写匹配 ~* 为不区分大小写匹配 !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 文件及目录匹配 -f ...

  7. 2019.01.08 bzoj3809: Gty的二逼妹子序列(莫队+权值分块)

    传送门 题意:多组询问,问区间[l,r]中权值在[a,b]间的数的种类数. 看了一眼大家应该都知道要莫队了吧. 然后很容易想到用树状数组优化修改和查询做到O(mnlogamax)O(m\sqrt nl ...

  8. CAS 单点登录 服务器整合

    概述 现在企业内部的系统越来越多,如果各个应用都有自己的用户系统,那么用户将不得不要记住不同系统的用户名密码,因此独立的用户系统应运而生,各个系统之间通过单点登录的方式,这样内部只需要记住一个用户名和 ...

  9. flex布局中的主轴和侧轴的确定

    1.主轴和侧轴是通过flex-direction确定的 如果flex-direction是row或者row-reverse,那么主轴就是justify-contain 如果flex-direction ...

  10. denyhost安装脚本

    #!/bin/bashDENYHOSTS=DenyHosts-2.6.tar.gzDENYHOSTS_VERSION=DenyHosts-2.6DENYHOSTS_URL=http://192.168 ...