//
// ChoiceBtn.h
// Guitar
//
// Created by tt1 on 15/11/29.
// Copyright © 2015年 Ji Miao. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ChoiceBtn : UIButton
@end
//
// ChoiceBtn.m
// Guitar
//
// Created by tt1 on 15/11/29.
// Copyright © 2015年 Ji Miao. All rights reserved.
//
#import "ChoiceBtn.h"
@implementation ChoiceBtn
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//可根据自己的需要随意调整
self.titleLabel.textAlignment=NSTextAlignmentLeft;
self.titleLabel.font=TTCommonFont(14);
self.imageView.contentMode=UIViewContentModeRight;
}
return self;
}
//更具button的rect设定并返回文本label的rect
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
CGFloat titleW = contentRect.size.width;
CGFloat titleH = contentRect.size.height;
CGFloat titleX = 0;
CGFloat titleY = 0;
contentRect = (CGRect){{titleX,titleY},{titleW,titleH}};
return contentRect;
}
//更具button的rect设定并返回UIImageView的rect
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
CGFloat imageW = 8;
CGFloat imageH = 8;
CGFloat imageX = contentRect.size.width-8;
CGFloat imageY = 10;
contentRect = (CGRect){{imageX,imageY},{imageW,imageH}};
return contentRect;
}
@end
这是自己亲自写的代码,大家可以试试写个自己的demo