UIButton的简单使用

UIButton

button.adjustsImageWhenDisabled = NO;  //当设置按钮不可用时,按钮的颜色会变化,此属性来控制这个功能是否开启,设置为NO时,颜色不变

button.adjustsImageWhenHighlighted = NO; //当按钮处于高亮状态时,按钮颜色不变

reversesTitleShadowWhenHighlighted       //当按钮处于高亮状态时,标题的阴影是否改变

showsTouchWhenHighlighted                 //点击按钮时是否让其发光

tintColor                                                //提示的颜色






//设置按钮中的内容里四个边界的距离 四个参数分别代表的是距离上,左,下,右边界的距离,如果本身距边界距离大于参数,则布局不变

button.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);    

同上

imageEdgeInsets

titleEdgeInsets


//当前按钮的标题,只读方法

currentAttributedTitle  

NSAttributedString *currentAttributedTitle = button.currentAttributedTitle;  //但是按钮的标题默认为空


currentBackgroundImage    当前按钮的背景,只读

UIImage image = button. currentBackgroundImage ;


currentImage     当前按钮的图片,只读

currentTitle  当前标题,只读,反悔类型为NSString

currentTitleColor  只读


titleLabel  只读    显示currentTitle的视图

currentTitleShadowColor 只读


METHOD

- (UIImage *)imageForState:(UIControlState)state   //返回某个状态下使用的图片


- (void)setAttributedTitle:( NSAttributedString  *) title  forState:( UIControlState ) state    设置标题

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state   设置背景图片

- (void)setImage:(UIImage *)image forState:(UIControlState)state    设置按钮图片

- (void)setTitle:(NSString *)title forState:(UIControlState)state    设置标题

- (void)setTitleColor:( UIColor  *) color  forState:( UIControlState ) state   设置标题字体

- (void)setTitleShadowColor:( UIColor  *) color  forState:( UIControlState ) state    设置标题阴影

- (UIColor *)titleColorForState:(UIControlState)state              返回某个状态下提示的颜色

- (NSString *)titleForState:(UIControlState)state                      返回某个状态下的标题

- (UIColor *)titleShadowColorForState:(UIControlState)state     返回某个状态下的标题阴影颜色

- (CGRect)backgroundRectForBounds:(CGRect)bounds                      返回控件的背景CGRect     bound是接收着的CGRect

- (CGRect)contentRectForBounds:(CGRect)bounds                            返回内容的CGRect     bound是接收着的CGRect

- (CGRect)imageRectForContentRect:(CGRect)contentRect                返回控件的图片CGRect    contentRect是内容的CGRect



添加点击事件

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







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值