自定义一个图片放在按钮右边位置的按钮
1。WQTitleButton.h
#import <UIKit/UIKit.h>
@interface WQTitleButton : UIButton
@end
1.WQTitleButton.m
#import "WQTitleButton.h"
#define ImageW 30
@implementation WQTitleButton
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
if (self = [super initWithCoder:aDecoder]) {
//设置图片显示的样式
self.imageView.contentMode = UIViewContentModeCenter;
}
return self;
}
-(CGRect)titleRectForContentRect:(CGRect)contentRect{
CGFloat titleW = contentRect.size.width-ImageW;
CGFloat titleH = contentRect.size.height;
return CGRectMake(0, 0, titleW, titleH);
}
-(CGRect)imageRectForContentRect:(CGRect)contentRect{
CGFloat imageW = ImageW;
CGFloat imageH = contentRect.size.height;
CGFloat imageX = contentRect.size.width-ImageW;