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];
}
}
iOS笔记之UIKit_UIButton的更多相关文章
- 荼菜的iOS笔记--UIView的几个Block动画
前言:我的第一篇文章荼菜的iOS笔记–Core Animation 核心动画算是比较详细讲了核心动画的用法,但是如你上篇看到的,有时我们只是想实现一些很小的动画,这时再用coreAnimation就会 ...
- IOS笔记 1
< ![CDATA[ 笔记 UIWindows 与UIView的关系iOS的坐标系统视图层次结构视图坐标(Frame和Bounds区别)UIView的常用属性和方法坐标系统的变换UIView内容 ...
- 【转】iOS笔记-自定义控件(OC)
原文网址:http://www.jianshu.com/p/f23862eb7b8a 导读: iOS开发中,很多时候系统提供的控件并不能很好的满足我们的需求,因此,自定义控件便成为搭建UI界面中必不可 ...
- iOS笔记———数据存储
应用沙盒:应用文件系统的根目录,每个应用都有独自的沙盒相互:在xcode中可以用NSHomeDirectory()函数,打印当前应用的沙盒根路径. 应用程序包:包含了所有资源文件和执行文件; * Do ...
- Xamarin开发IOS笔记:切换输入法时输入框被遮住
在进行IOS开发的过程中,出现类似微信朋友圈的交互界面,当用户遇到感兴趣的内容可以进行评论.为了方便评论输入,当出现评论输入框的时候自动将评论输入框移动至键盘的上方,这样方便边输入边查看. 当用户隐藏 ...
- 【IOS笔记】Delegation
Delegation Delegation is a simple and powerful pattern in which one object in a program acts on beha ...
- 【IOS笔记】Event Delivery: The Responder Chain
Event Delivery: The Responder Chain 事件分发--响应链 When you design your app, it’s likely that you want t ...
- 【IOS笔记】Gesture Recognizers
Gesture Recognizers Gesture recognizers convert low-level event handling code into higher-level acti ...
- 【IOS笔记】About Events in iOS
About Events in iOS Users manipulate their iOS devices in a number of ways, such as touching the scr ...
随机推荐
- XiaoKL学Python(C)__future__
__future__ in Python 1. from __future__ import xxxx 这是为了在低版本的python中使用可能在某个高版本python中成为语言标准的特性,从而 在将 ...
- 单细胞RNA测序技术之入门指南
单细胞RNA测序技术之入门指南 [字体: 大 中 小 ] 时间:2018年09月12日 来源:生物通 编辑推荐: 在这个飞速发展的测序时代,DNA和RNA测序已经逐渐成为“实验室中的家常菜”.若要 ...
- MyBatis Generator中文文档
MyBatis Generator中文文档 MyBatis Generator中文文档地址: http://mbg.cndocs.tk/ 该中文文档由于尽可能和原文内容一致,所以有些地方如果不熟悉,看 ...
- 07. pt-fifo-split
iostat -dxm 1 42 1>iostat.log 2>&1 ---------------------------------------- #!/bin/bash of ...
- FoxMail提示:请求的名称有效,但是找不到请求的类型的数据
FoxMail发送或者接收邮件的时候,提示如下信息: <错误信息:请求的名称有效,但是找不到请求的类型的数据> 一,DNS解析不稳定 解决办法:修改本地电脑上面本地连接中的DNS地址< ...
- windows mysql主 Linux mysql 从 主从同步,读写分离
Mysql –master linux-slave 一.My.ini: Server-id=1 relay-log=relay-bin relay-log-index=relay-bin-index ...
- 设计模式之生成者模式java源代码
假设要组装一辆自行车,并且自行车就是车轮和车架组成. Builder对应于组装自行车所使用的车轮和车架 ConcreteBuiler对应于自行车的车轮和车架,同时可以返回一辆自行车. Product对 ...
- Mysql遇到的坑
2018-04-09 这个虽然跟粗心有关,但是Mysql没报错是哪般? select sum(play_count) from tb_user_login where user_id = 61 and ...
- 【Web】Sublime Text 3 连接sftp/ftp(远程服务器)
在 Win 下常用 Xftp 软件来和远程服务传递文件,但是要是在项目开发的时候频繁的将远程文件拖到本地编辑然后再传回远程服务器,那真是麻烦无比,但是Sublime中SFTP插件,它让这世界美好了许多 ...
- java ajax请求后台并获取到返回值
js: $.ajax({ url : '../Islogin.do', type : 'get', cache : false, dataType : 'json', success : functi ...