UIButton

基本属性

  1. contentEdgeInsets, titleEdgeInsets, imageEdgeInsets: 调整边距的三个属性.详细介绍
  2. reversesTitleShadowWhenHighlighted: 设置高亮时是否改变阴影.
  3. adjustsImageWhenHighlighted: 高亮状态下,image深一点.
  4. adjustsImageWhenDisabled: 被禁用状态,image浅一点.
  5. showsTouchWhenHighlighted: 触摸时候,会发光.
  6. tintColor: 所有的常用控件,都有tintColor属性。其中,UIView也有这个属性,可想而知继承UIView的控件也都有tintColor了。使用场景:当父视图更改了tintColor为red,那么它所有的一级子视图tintColor全部为red,除非你主动设置过子视图的tintColor。它再往下的子视图的tintColor则遵循直接父视图的tintColor 。
  7. buttonType: 按钮类型.
  8. currentTitle: 按钮当前的标题.(只读)
  9. currentTitleColor: 当前title颜色.(只读)
  10. currentTitleShadowColor:当前title阴影颜色.(只读)
  11. currentImage: 当前image.(只读)
  12. currentBackgroundImage:当前背景图片.(只读)
  13. currentAttributedTitle:当前富文本.(只读)
  14. titleLabel:存放标题的label.(只读)
  15. imageView:存放图片的imageView.(只读)

方法

//设置某种状态下的标题
- (void)setTitle:(nullable NSString *)title forState:(UIControlState)state; 
//设置某种状态下标题的颜色
- (void)setTitleColor:(nullable UIColor *)color forState:(UIControlState)state ;
//设置title在不同状态下的阴影颜色
- (void)setTitleShadowColor:(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;

//根据不同状态获取相关属性.
- (nullable NSString *)titleForState:(UIControlState)state; 
- (nullable UIColor *)titleColorForState:(UIControlState)state;
- (nullable UIColor *)titleShadowColorForState:(UIControlState)state;
- (nullable UIImage *)imageForState:(UIControlState)state;
- (nullable UIImage *)backgroundImageForState:(UIControlState)state;
- (nullable NSAttributedString *)attributedTitleForState:(UIControlState)state;

//可以自定义绘制
- (CGRect)backgroundRectForBounds:(CGRect)bounds;
- (CGRect)contentRectForBounds:(CGRect)bounds;
- (CGRect)titleRectForContentRect:(CGRect)contentRect;
- (CGRect)imageRectForContentRect:(CGRect)contentRect;

你可能感兴趣的:(UI基本控件)