UIButton-详解

一、按钮的状态

按钮的状态
 //1.UIControlStateNormal
 1> 除开UIControlStateHighlighted、UIControlStateDisabled、UIControlStateSelected以外的其他情况,都是normal状态
 2> 这种状态下的按钮【可以】接收点击事件
 
 //2.UIControlStateHighlighted
 1> 【当按住按钮不松开】或者【highlighted = YES】时就能达到这种状态
 2> 这种状态下的按钮【可以】接收点击事件
 
 //3.UIControlStateDisabled
 1> 【button.enabled = NO】时就能达到这种状态
 2> 这种状态下的按钮【无法】接收点击事件
 
 //4.UIControlStateSelected
 1> 【button.selected = YES】时就能达到这种状态
 2> 这种状态下的按钮【可以】接收点击事件

二、按钮无法点击

让按钮无法点击的2种方法
 //1> button.enabled = NO;
 *【会】进入UIControlStateDisabled状态
 
 //2> button.userInteractionEnabled = NO; 
 *【不会】进入UIControlStateDisabled状态,继续保持当前状态

三、获取按钮的当前标题

//titleLabel.text 要根据状态取,一般采用currentTitle
//self.titleUnderline.width = [titleButton.currentTitle sizeWithFont:titleButton.titleLabel.font].width;
//NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
//attributes[NSFontAttributeName] = titleButton.titleLabel.font;
//self.titleUnderline.width = [titleButton.currentTitle sizeWithAttributes:attributes].width;
self.titleUnderline.width = titleButton.titleLabel.width + 10;

四 、按钮内部子控件对齐

 // 控制按钮内部的子控件对齐,不是用contentMode,是用以下2个属性
 //    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
 //    btn.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;

 五、按钮内部子控件的间距

// 控件按钮内部子控件之间的间距
//    btn.contentEdgeInsets = UIEdgeInsetsMake(10, 0, 0, 0);
//    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
//    btn.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);

 

 

 

 

 

posted @ 2018-12-12 10:03  淡然微笑_Steven  阅读(283)  评论(0编辑  收藏  举报