UIButtont特殊样式
2015-09-04 10:16
369 查看
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];
button.frame =CGRectMake(100, 100, 100, 30);
//设置显示文本
//因为按钮有多种状态(Normal,Highlighted,UIControlStateDisabled),需要给不同状态设置文本
//UIControlState
表示控件状态
[button setTitle:@"我是按钮,点我啊"forState:UIControlStateNormal];
[self.viewaddSubview:button];
//按钮添加点击事件处理
//参数1:传入一个对象执行,
表示那个对象处理事件,一般传入self
//参数2:传入方法的selector,
表示那个方法处理事件
//参数3:传入事件类型,
最常用TouchUpInside,参数类型UIControlEvent
//按下触发事件: UIControlEventTouchDown
[button addTarget:selfaction:@selector(buttonClicked:)forControlEvents:UIControlEventTouchUpInside];
//2.常用属性
//设置文本颜色
[button setTitleColor:[UIColorredColor]
forState:UIControlStateNormal];
//设置文本字体
button.titleLabel.font = [UIFontsystemFontOfSize:12];
//设置圆角矩形按钮
button.backgroundColor = [UIColorwhiteColor];
//设置圆角大小
button.layer.cornerRadius = 10;
//设置剪切(否则有的时候设置圆角没效果)
button.clipsToBounds =YES;
//点击位置高亮效果
button.showsTouchWhenHighlighted =YES;
//禁止点击
button.enabled =NO;
self.view.backgroundColor = [UIColorlightGrayColor];
//3.图片按钮的使用
UIButton *imageButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
imageButton.frame =CGRectMake(100, 200, 150, 30);
//设置背景图片
UIImage *image = [UIImageimageNamed:@"back.png"];
[imageButton setBackgroundImage:imageforState:UIControlStateNormal];
[self.viewaddSubview:imageButton];
//设置前景(文本和图片)
[imageButton setTitle:@"图片安妮"forState:UIControlStateNormal];
[imageButton setTitleColor:[UIColorblueColor]
forState:UIControlStateNormal];
[imageButton setImage:[UIImageimageNamed:@"city_select.png"]forState:UIControlStateNormal];
[imageButton addTarget:selfaction:@selector(imageBtnClick)forControlEvents:UIControlEventTouchUpInside];
//调整按钮中文本和图片位置
// top, left, bottom, right
imageButton.titleEdgeInsets =UIEdgeInsetsMake(0, -100, 0, 0);
imageButton.imageEdgeInsets =UIEdgeInsetsMake(0, 80, 0, 0);
<
97d9
p class="p5">
;
button.frame =CGRectMake(100, 100, 100, 30);
//设置显示文本
//因为按钮有多种状态(Normal,Highlighted,UIControlStateDisabled),需要给不同状态设置文本
//UIControlState
表示控件状态
[button setTitle:@"我是按钮,点我啊"forState:UIControlStateNormal];
[self.viewaddSubview:button];
//按钮添加点击事件处理
//参数1:传入一个对象执行,
表示那个对象处理事件,一般传入self
//参数2:传入方法的selector,
表示那个方法处理事件
//参数3:传入事件类型,
最常用TouchUpInside,参数类型UIControlEvent
//按下触发事件: UIControlEventTouchDown
[button addTarget:selfaction:@selector(buttonClicked:)forControlEvents:UIControlEventTouchUpInside];
//2.常用属性
//设置文本颜色
[button setTitleColor:[UIColorredColor]
forState:UIControlStateNormal];
//设置文本字体
button.titleLabel.font = [UIFontsystemFontOfSize:12];
//设置圆角矩形按钮
button.backgroundColor = [UIColorwhiteColor];
//设置圆角大小
button.layer.cornerRadius = 10;
//设置剪切(否则有的时候设置圆角没效果)
button.clipsToBounds =YES;
//点击位置高亮效果
button.showsTouchWhenHighlighted =YES;
//禁止点击
button.enabled =NO;
self.view.backgroundColor = [UIColorlightGrayColor];
//3.图片按钮的使用
UIButton *imageButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
imageButton.frame =CGRectMake(100, 200, 150, 30);
//设置背景图片
UIImage *image = [UIImageimageNamed:@"back.png"];
[imageButton setBackgroundImage:imageforState:UIControlStateNormal];
[self.viewaddSubview:imageButton];
//设置前景(文本和图片)
[imageButton setTitle:@"图片安妮"forState:UIControlStateNormal];
[imageButton setTitleColor:[UIColorblueColor]
forState:UIControlStateNormal];
[imageButton setImage:[UIImageimageNamed:@"city_select.png"]forState:UIControlStateNormal];
[imageButton addTarget:selfaction:@selector(imageBtnClick)forControlEvents:UIControlEventTouchUpInside];
//调整按钮中文本和图片位置
// top, left, bottom, right
imageButton.titleEdgeInsets =UIEdgeInsetsMake(0, -100, 0, 0);
imageButton.imageEdgeInsets =UIEdgeInsetsMake(0, 80, 0, 0);
<
97d9
p class="p5">
;
相关文章推荐
- UILabe的特殊格式
- UIView
- UITextField
- UIImageView以及动画
- Android Studio创建module缺少build文件夹
- String,StringBuffer与StringBuilder的区别??
- 原来UIWindow可以自定义frame
- sort与priority_queue的比较标准差异
- UILabel的文字与 label 的中间线对齐方式
- UILabel.text截取方式
- HDU 1005 Number Sequence(数论)
- POJ 2034 Anti-prime Sequences(数论+dfs)
- POJ 2478 Farey Sequence(欧拉函数)
- PHP基础----PHP常用功能----09include 与 require
- UI控件-----UIScrollView
- Leetcode Unique Binary Search Trees II
- Android酷炫的UI开源框架(转)
- hdu 4915 Parenthese sequence(贪心,模拟)
- IOS开发UI—Button基础
- UITextField相关使用方法