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 ...
随机推荐
- http协议(四)http常用状态码
一:http状态码 表示客户端http请求的返回结果.标记服务器端的处理是否正常.通知出现的错误等工作 状态码的类别如下: http状态码种类繁多,大概有60多种,实际上经常使用的只有14种,下面为一 ...
- 异步Servlet和异步过虑器
异步处理功能可以节约容器线程.此功能的作用是释放正在等待完成的线程,是该线程能够被另一请求所使用. 要编写支持异步处理的 Servlet 或者过虑器,需要设置 asyncSupported 属性为 t ...
- 拼图类APP原型模板分享——简拼
简拼是一款记录美好.抒写情怀的拼图APP,模板设计风格简约文艺,种类齐全. 此原型模板所用到的组件有标签组.水平分隔线.圆形工具.交互动作有结合标签组实现页面跳转,选择组件触发按钮状态变化等. 此原型 ...
- mysql8.0.4以后修改密码方式变更
https://blog.csdn.net/qq_38265784/article/details/80915098 use mysql: ALTER USER 'root'@'localhost' ...
- java 多态的深入理解
简单来说 : 多态 能够很好的解决代码耦合性的问题 考虑这样一个场景 有个人 买了辆捷达汽车 .这个系统应该如何设计呢? public class JettaCar { public void run ...
- ubuntu的应用中心打不开、闪退
原因没有细究,但问题已经解决简单粗暴: 1.更新列表 apt-get update apt-get dist-upgrade 2.重新安装应用中心 apt-get install --reinsta ...
- 859. Buddy Strings
class Solution { public: bool buddyStrings(string A, string B) { int lenA=A.length(); int lenB=B.len ...
- join和split 的使用
var abc = new Array(a,b,c,d,e); abc.join('-') // 结果 : a-b-c-d-e-f var obk = 'a-b-c-d-e'; obk.split(' ...
- Educational Codeforces Round 62 E 局部dp + 定义状态取消后效性
https://codeforces.com/contest/1140/problem/E 局部dp + 定义状态取消后效性 题意 给你一个某些位置可以改变的字符串,假如字符串存在回文子串,那么这个字 ...
- IntellJ IDEA2017 springboot2.0.2 替代@SpringBootApplication方式
如果不想用@SpringBootApplication,那么可以用@EnableAutoConfiguration 和@ComponentScan替代@SpringBootApplication 详情 ...