标签:
首先需要说明UIButton继承自UIControl,UIControl继承自UIView
常用属性
调整titleLabel和imageView的相对位置
1.
2.@property (nonatomic) UIEdgeInsets titleEdgeInsets;
3.@property (nonatomic) UIEdgeInsets imageEdgeInsets;
titleLabel和imageView
1.@property (nonatomic,readonly,strong) UILabel *titleLabel;
2.@property (nonatomic,readonly,strong) UIImageView *imageView;
需要注意的是:修改title的字体大小
1.button.titleLabel.font = [UIFont systemFontOfSize:14.0f];
继承自UIControl的属性
1.@property(nonatomic,getter=isEnabled) BOOL enabled; // default is YES. if NO, ignores touch events and subclasses may draw differently
2.@property(nonatomic,getter=isSelected) BOOL selected;
3.// default is NO.
4.@property(nonatomic,getter=isHighlighted) BOOL highlighted;
5.// default is NO.
6.@property(nonatomic,readonly) UIControlState state;
常用方法
- (void)setTitle:(nullable NSString *)title forState:(UIControlState)state;
- (void)setTitleColor:(nullable UIColor *)color forState:(UIControlState)state
- (void)setImage:(nullable UIImage *)image forState:(UIControlState)state;
- (void)setBackgroundImage:(nullable UIImage *)image forState:(UIControlState)state
- (void)setAttributedTitle:(nullable NSAttributedString *)title forState:(UIControlState)state
1.
2.- (CGRect)titleRectForContentRect:(CGRect)contentRect;
3.- (CGRect)imageRectForContentRect:(CGRect)contentRect;
4.
- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
- (void)removeTarget:(nullable id)target action:(nullable SEL)action forControlEvents:(UIControlEvents)controlEvents;
示例:展示调整titleLabel 和 imageView 位置,默认是图片在左,文字在右。但是在此,我想让图片在上,文字在下。
1.
2.button.titleEdgeInsets = UIEdgeInsetsMake(100, -100, 0, 0);
3.button.imageEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
4.
标签:
原文地址:http://www.cnblogs.com/buakaw/p/5069716.html