作为一个菜鸟程序员,应该时常记录知识点并为其分类,让自己慢慢成长起来,所以在此做一些记录,也为后续的想学习的人参考。
1创建UIButton *btn=[[UIButton alloc] init] ;或者UIButton *btn = [UIButton buttonWithType:(UIButtonType)];
2 UIButton的UIButtonType
UIButtonTypeCustom = 0, //这个可以用来自定义按钮
UIButtonTypeRoundedRect, // 圆角按钮
UIButtonTypeDetailDisclosure, //蓝色的圆形小箭头按钮
UIButtonTypeInfoLight, //圆形的中间有个小写i的按钮(白色的)
UIButtonTypeInfoDark, //圆形的中间有个小写i的按钮(黑色的)
UIButtonTypeContactAdd, //带加号的按钮
3 UIButton.Label.text设置的button的标题可能不会显示
使用[button setTitle:forState:]来设置button的标题在某状态下 当然你也可以自己创建一个label然后[button addsubview:label];
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state; //设置标题颜色在某状态下
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state; // 设置标题阴影颜色在某状态下
- (void)setImage:(UIImage *)image forState:(UIControlState)state; //设置button的图片(这个图片并不是背景图,如果设置了图片button的标题是显示不出来的,若想显示图片又要显示标题可将图片设为button的背景图)
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state; // 设置button的背景图
设置在点击的一瞬间按钮变换图片,按钮弹起恢复图片
(
[doneButton setImage:[UIImageimageNamed:@"键盘确认亮.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImageimageNamed:@"键盘确认暗.png"] forState:UIControlStateHighlighted];
)
以上是button常用的方法此外button还有好多方法可根据名字猜到其用法
4
[ button addTarget:(id) action:(SEL) forControlEvents:(UIControlEvents)]可用来设置 button的点击方法,第二个参数为@select(方法名)指定点击触发的方法
button.enabled来设置是否禁掉button,属性enabled为BOOL值yes则button可用,NO禁掉button;
showsTouchWhenHighlighted一个BOOL值,YES的时候关掉点击时的高亮效果,默认值为NO。