UIButton

       作为一个菜鸟程序员,应该时常记录知识点并为其分类,让自己慢慢成长起来,所以在此做一些记录,也为后续的想学习的人参考

        

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。

 

 

 

转载于:https://www.cnblogs.com/aoxiaohongchen/archive/2012/12/31/2840525.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值