封装实现UIButton左文字右图片

#import "TitleButton.h"

@implementation TitleButton

- (instancetype)initWithFrame:(CGRect)frame {

    if (self = [super initWithFrame:frame]) {

        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        self.titleLabel.font = [UIFont boldSystemFontOfSize:16];

   [self setTitle:@"title" forState:UIControlStateNormal];

        [self setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];

        [self setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateSelected];

     }

    return self;

}

 

/** 设置内部imageViewframe */

//- (CGRect)imageRectForContentRect:(CGRect)contentRect

//{

//    CGFloat x = ;

//    CGFloat y = ;

//    CGFloat width = ;

//    CGFloat height = ;

//    return CGRectMake(x, y, width, height)

//}

/** 设置内部titleLabelframe */

//- (CGRect)titleRectForContentRect:(CGRect)contentRect

//{

//    CGFloat x = ;

//    CGFloat y = ;

//    CGFloat width = ;

//    CGFloat height = ;

//    return CGRectMake(x, y, width, height)

//    

//}

- (void)layoutSubviews

{

    [super layoutSubviews]; 

    //titleLablex

    self.titleLabel.x = 0;

    //imageViewx

    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame) ;

}

posted @ 2016-02-05 15:05  starainDou  阅读(288)  评论(0编辑  收藏  举报