自定义button会用到的四个方法
// 返回背景边界(background)
- (CGRect)backgroundRectForBounds:(CGRect)bounds;
// 返回内容边界 标题+图片+标题与图片之间的间隔(title + image + the image and title separately)
- (CGRect)contentRectForBounds:(CGRect)bounds;
// 返回标题边界
- (CGRect)titleRectForContentRect:(CGRect)contentRect;
// 返回图片边界
- (CGRect)imageRectForContentRect:(CGRect)contentRect;
调用它们的时机:
1.当button上什么也没有加时,只会调用- (CGRect)contentRectForBounds:(CGRect)bounds; 这一个方法。
2.当button只设置了title时,会调用- (CGRect)contentRectForBounds:(CGRect)bounds; 和- (CGRect)titleRectForContentRect:(CGRect)contentRect;
3.当设置了image时,会- (CGRect)contentRectForBounds:(CGRect)bounds; 和- (CGRect)imageRectForContentRect:(CGRect)contentRect;
4.单单设置了backgroundimage时,才会调用- (CGRect)backgroundRectForBounds:(CGRect)bounds;这个方法。而且不会调用imag和title那俩个方法
下面分别解释一下各个方法意思:
-(CGRect)backgroundRect