Button的功能很黄很暴力,即能显示文字,又能显示图片,还能随时调整内部图片和文字的位置,用的地方很多。

(1)按钮常用的四种状态:

  normal(普通状态)

  默认情况(Default)

  对应的枚举常量:UIControlStateNormal

  highlighted(高亮状态)

  按钮被按下去的时候(手指还未松开)

  对应的枚举常量:UIControlStateHighlighted

  selected (选中状态)

  选没选中由我们自行设定

  对应的枚举常量:UIControlStateSelected

  disabled(失效状态,不可用状态)

  如果enabled属性为NO,就是处于disable状态,代表按钮不可以被点击

  对应的枚举常量:UIControlStateDisabled

(2)创建button:+ (id)buttonWithType:(UIButtonType)buttonType;

typedef NS_ENUM(NSInteger, UIButtonType) {

UIButtonTypeCustom = 0,            // no button type

UIButtonTypeSystem,                // standard system button

UIButtonTypeDetailDisclosure,

UIButtonTypeInfoLight,

UIButtonTypeInfoDark,

UIButtonTypeContactAdd,

  常用的是UIButtonTypeCustom和UIButtonTypeSystem,一般选用UIButtonTypeSystem,当你需要对button进行一些个性化的设置时,比如button的选中状态与未选中状态,字体,图片这些不同时,就必须要选择UIButtonTypeCustom,不然,选中状态时,按钮的上面会出现一个蓝色的竖条条。

UIButtonTypeRoundedRect = UIButtonTypeSystem,   // Deprecated, use UIButtonTypeSystem instead

};

(2)按钮的常用属性

  Button.titleLabel.font = [UIFont systemFontOfSize:20];   //改变button字体大小

(3)button的描边

(4)button的四角设置弧度

(5)

(6)

(7)

(8)

(9)

(10)

- (void)viewDidLoad {

[super viewDidLoad];

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

button.frame = CGRectMake(100, 100, 200, 100);

//[button setTitle:@"呵呵..." forState:UIControlStateNormal];

//button.backgroundColor = [UIColor lightGrayColor];

//[button setTintColor:[UIColor yellowColor]];

button.titleLabel.text = @"hehe";

button.showsTouchWhenHighlighted=YES;

[button addTarget:self action:@selector(addButton:) forControlEvents:UIControlEventTouchUpInside];

//将标签加入视图

[self.view addSubview:button];

}

-(void)addButton:(UIButton*)button{

button.selected = !button.selected;

if (button.selected) {

NSLog(@"selected");

button.backgroundColor = [UIColor lightGrayColor];

[button setTitle:@"点我干嘛!" forState:UIControlStateNormal];

NSLog(@"%@",button.currentTitle);

} else {

NSLog(@"unSelected");

[button setTitle:@"呵呵..." forState:UIControlStateNormal];

NSLog(@"%@",button.currentTitle);

}

}

---恢复内容结束---

UIButton常用属性小结(编辑中。。。)的更多相关文章

  1. UILabel常用属性小结

    标签常用的属性: (1)frame属性:设置标签的位置与大小. frame = CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat heig ...

  2. 【iOS】UIButton 常用属性

    发现 UIButton 的相关属性不熟悉了……常用的一些属性代码如下: UIButton *add = [UIButton buttonWithType:UIButtonTypeCustom]; ad ...

  3. IOS UIButton常用属性

    //1.添加按钮 UIButton *nameView=[UIButton buttonWithType:UIButtonTypeCustom]; //nameView.backgroundColor ...

  4. Swift2.0 中的String(一):常用属性

    字符串算是平常用的比较多.花样也比较多的一个类型,昨天有空把相关的一些常用操作都写了一遍,总结出来.其实iOS里面的字符串更复杂,还有NSString系列等等,那些API太多将来需要用的时候再慢慢学. ...

  5. 给iOS开发新手送点福利,简述UIButton的属性和用法

    UIButton属性 1.UIButton状态: UIControlStateNormal          // 正常状态    UIControlStateHighlighted     // 高 ...

  6. UIButton的常用属性

    可以通过代码的方式创建UIButton 通用实例化对象方法: UIButton *button = [[UIButton alloc] initWithFrame:rect]; 快速实例化对象方法: ...

  7. DataGrid中的常用属性

    DataGrid中的常用属性 $('#dg').datagrid({ url:'datagrid_data.json', columns:[[ {field:'code',title:'Code',w ...

  8. Android开发中XML布局的常用属性说明

    <!-- 常用属性说明: android:id="@+id/button" 为控件指定Id android:text="NNNNNNNNNN" 指定控件的 ...

  9. Delphi中TStringList类常用属性方法详解

    TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 先把要讨论的几个属性列出来: 1.CommaText 2.Delim ...

随机推荐

  1. HDU-1072 Nightmare (bfs+贪心)

    Nightmare Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...

  2. Android平台设计规范整理(尺寸+组成元素+字体+滑块)

    转自:http://www.ui.cn/project.php?id=12394

  3. P2P应用中的NAT穿透问题

    多年前曾经写过一个关于NAT钻洞的实验.现在发现那个做法在我现在的路由器上已经不管用了.经过一番搜索发现时过境迁,世界变化很快,新路由器已经是UPnP了.在这里重新理一下几种方法. 第一种,也是不太靠 ...

  4. Excel 帮助类

    using System; using System.Collections.Generic; using System.Data; using System.Drawing; using Syste ...

  5. storm的并发

    1 storm并行的基本概念 storm集群中的一个机器可以运行一个或者多个worker,对应于一个或者多个topologies. 1个worker进程运行1个或多个excutor线程.每个worke ...

  6. codeforces div2 677 D

    http://codeforces.com/problemset/problem/677/D 题目大意: 给你一个n*m的图,上面有p种钥匙(p<=n*m),每种钥匙至少有一个,期初所有为1的钥 ...

  7. ural1542 Autocompletion

    Autocompletion Time limit: 2.0 secondMemory limit: 64 MB The Japanese are infinitely in love with ma ...

  8. POJ 3660 Cow Contest 弗洛伊德

    题意难懂是POJ的标配,这都TM赖本泽马. 题意:有N头牛进行了M场比赛,比赛双方是A - B 且总是A赢(前面的那个数赢),如果说A赢B,B赢C 则可以确定A赢C.问最终多少头牛的排名可以确定. 思 ...

  9. led.c驱动框架

    Makefile: obj-m += led.o ################################################ KERNEL = /home/linux--FS21 ...

  10. cmd 3389

    1.2000系统 简要说一下如何进行DNS溢出攻击.我用的溢出利用程序是dns.exe,在CMD下运行它可以看到它的使用参数等信息.执行"dns -s IP"命令检测目标IP是否存 ...