UIButton总结
2016-02-23 15:22
337 查看
概念:
UIButton的类是一个UIControl子类,它实现了在触摸屏上的按钮。触摸一个按钮拦截事件和动作消息发送到目标对象时,它的挖掘。设定的目标和行动方法都继承自UIControl。这个类提供了方法来设置标题,图像,按钮等外观属性。通过使用set方法,你可以指定一个不同的外观为每个按钮状态。
创建:
//创建圆角button
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
//指定button的位置和大小
button.frame = CGRectMake(10, 10, 75, 75);
//给button设置标签,用来辨别点击的是哪个button,常用在委托方法中。
button.tag = 0;
//定义按钮标题
[button setTitle:@"Button Title" forState:UIControlStateNormal];
//定义按钮标题字体格式
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
//给button添加委托方法,即点击触发的事件。
[button addTarget:selfaction:@selector(touchButton1:) forControlEvents :UIControl EventTouchUp Inside];
//给button添加图片
[button setImage:[UIImageimageNamed:@"blue_bg(2).png"] forState:UIControlStateNormal];
//将button加入视图当中
[view addSubview:button];
UIButton的类是一个UIControl子类,它实现了在触摸屏上的按钮。触摸一个按钮拦截事件和动作消息发送到目标对象时,它的挖掘。设定的目标和行动方法都继承自UIControl。这个类提供了方法来设置标题,图像,按钮等外观属性。通过使用set方法,你可以指定一个不同的外观为每个按钮状态。
创建:
//创建圆角button
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
//指定button的位置和大小
button.frame = CGRectMake(10, 10, 75, 75);
//给button设置标签,用来辨别点击的是哪个button,常用在委托方法中。
button.tag = 0;
//定义按钮标题
[button setTitle:@"Button Title" forState:UIControlStateNormal];
//定义按钮标题字体格式
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
//给button添加委托方法,即点击触发的事件。
[button addTarget:selfaction:@selector(touchButton1:) forControlEvents :UIControl EventTouchUp Inside];
//给button添加图片
[button setImage:[UIImageimageNamed:@"blue_bg(2).png"] forState:UIControlStateNormal];
//将button加入视图当中
[view addSubview:button];
相关文章推荐
- UIALertView的使用
- UiAutomator 测试环境搭建
- <%@ page trimDirectiveWhitespaces="true" %>
- POJ 2524 Ubiquitous Religions(简单的并查集题目)
- 图片动画
- masonry+UIScrollView+UICollectionView自动布局偶尔向下偏移的问题
- UIViewController界面跳转时的值传递
- UIView
- easyUI 中datagrid控件从后台获取数据生成列,想让其中部分属性数据不在表中显示
- 我的Android进阶之旅------>解决:Failed to create 'build\outputs\apk\watch-debug-unaligned.apks': 拒绝访问。
- VS2008LINK : fatal error LNK1000: Internal error during IncrBuildImage
- bluetooth-蓝牙事件监听
- CoreBluetooth第二节:Performing Common Peripheral Role Task(执行常见的外设端任务)
- iOS开发技巧(系列十二:UUID和UDID的区别)
- mui如何增加自定义字体icon图标
- 详解 CALayer 和 UIView 的区别和联系
- iOS 5.0 后UIViewController新增:willMoveToParentViewController和didMoveToParentViewController
- easyUI 中datagrid控件demo,包括选中一行能读取到数据
- UIView和CALayer的区别 说的比较清楚了
- iOS-UItableview 分割线(自定义+原生)方法总结