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 ...
随机推荐
- POJ 3621Sightseeing Cows 0/1 分数规划
Description 作为对奶牛们辛勤工作的回报,Farmer John决定带她们去附近的大城市玩一天.旅行的前夜,奶牛们在兴奋地 讨论如何最好地享受这难得的闲暇. 很幸运地,奶牛们找到了一张详细的 ...
- Codeforces 545E. Paths and Trees 最短路
E. Paths and Trees time limit per test: 3 seconds memory limit per test: 256 megabytes input: standa ...
- 杭电1518 Square(构成正方形) 搜索
HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- UI设计教程分享:关于海报的合成过程
一张好的产品创意合成海报,能瞬间提升商品价值感,同时场景和相关元素的融入,让消费者瞬间明白商品属性及内涵.同时为商品营造的使用场景拥有更强的代入感,从而刺激转化.好的创意合成海报能为消费者带来视觉冲击 ...
- 测试 Open Live Writer
我要试试. 看看图片如何: 这是从电脑端上传的一个例子,如果编辑器里可以支持复制粘贴图片就好了. Open Live Writer 发布以后,还可在保存在本地,想起来的时候就修改一下. 再美化一下. ...
- [Robot Framework] 动态等待,提供默认的等待时间,等待时间可传可不传
默认10s
- pytho常用模块2——random
random模块用来生成随机数,有以下几个常用方法: import random random.random() #产生随机数[0-1) random.randint(a,b) #产生随机整数[a,b ...
- OCIlib的几个函数的执行效率(附上pro*c的性能对比)
ocilib提供了以下几个执行sql语句的函数 OCI_ExecuteStmt/OCI_ExecuteStmtFmt 使用没有绑定变量的语句 OCI_Execute 使用有绑定变量的语句 OCI_Im ...
- python - package - bs4 - 美味汤
Beautiful Soup 3 only works on Python 2.x, but Beautiful Soup 4 also works on Python 3.x. 你可能在寻找 Bea ...
- zookeeper集群的搭建(三台相同)
查看jdk java -version 卸载自带jdk rpm -qa|grep java rpm -e --nodeps tzdata-java-2015e-1.el6.noarch rpm -e ...