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 ...
随机推荐
- linux中的定时任务创建
1.查看root用户身份下正常运行的定时任务 crontab -l -u XXX 列出XXX用户的所有定时任务,如有没有会提示 no crontab for XXX列出所有的用户:cat /etc/p ...
- mysql使用存储过程,自动生成新的表单
use mydb; delimiter // CREATE procedure create_table(In imax int) BEGIN DECLARE `@i` int(11); D ...
- 利用sql的OVER()PARTITION 找到最相近的数值
前几天同事问我一个问题,能不能用sql搞定这个问题: 我这里有一个张表table1中有time1,value1,有表table2有字段time2,value2. 现在要把table2中的value2更 ...
- Nowcoder 练习赛26E 树上路径 - 树剖
Description 传送门 给出一个n个点的树,1号节点为根节点,每个点有一个权值 你需要支持以下操作 1.将以u为根的子树内节点(包括u)的权值加val 2.将(u, v)路径上的节点权值加va ...
- Nowcoder OI赛制测试2 F 假的数学题 - 斯特林公式 + 二分
Description 给定$X$, 找到最小的$N$ 使得$N! > X^X$ 数据范围: $x <= 1e11$ Solution $X^X$ 太大, 高精也存不过, 所以取对数 : ...
- UVA-1364.Knights of the Round Table 无向图BCC
题目链接:https://vjudge.net/problem/UVA-1364 题意:有n个人参加会议,互相憎恨的人不能坐在相邻的位置,并且每个会议参加的人数必须是奇数,求有多少个人不能参加任何一个 ...
- ui设计用什么软件
Ui设计用什么软件?作为ui设计师,你必须要熟练的使用以下几款设计软件,不然可能也无法胜任ui设计师的职位. ui设计除了要学习一些基本的操作软件,如PS AI AE AXURE 以外呢,还要学习比如 ...
- mac install brew
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ...
- sql server profiler 工具使用 sql 语句性能分析
https://www.cnblogs.com/knowledgesea/p/3683505.html
- asp.net query string 及 form data 遇到的编码问题
当遇到此问题时,脑海里闪过的第一个解决方案是设置 web.config 的编码.但一想,就某一个页面的需求而导致其他跟着妥协,不是好的解决方案.于是网上搜索答案,下面做个小分享,遗憾的是研究不够深入, ...