UIButton 解耦

20161110

继续解耦,

//DENG
    CGRect theFrame = cell.nickNameLabel.frame;
    theFrame.origin.y = 18;
    cell.nickNameLabel.frame = theFrame;
    return cell;




http://blog.sina.com.cn/s/blog_a573f7990101cdpe.html

UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout







见过的 最漂亮 的一次 解耦:

2016 10 28



import

@interface FSVerticalRankImageTitleButton : UIButton
@property (nonatomic, assign)CGFloat imageCenterY;
@property (nonatomic, assign)CGFloat titleOriginY;
@end



import "FSVerticalRankImageTitleButton.h"

@implementation FSVerticalRankImageTitleButton

-(void)layoutSubviews {
[super layoutSubviews];

// Center image
CGPoint center = self.imageView.center;
center.x = self.frame.size.width/2;
center.y =_imageCenterY; //self.imageView.frame.size.height/2;
self.imageView.center = center;

//Center text
CGRect newFrame = [self titleLabel].frame;
newFrame.origin.x = 0;
newFrame.origin.y =_titleOriginY; //self.imageView.frame.size.height + 5;
newFrame.size.width = self.frame.size.width;

self.titleLabel.frame = newFrame;
self.titleLabel.textAlignment =NSTextAlignmentCenter;

}

@end

你可能感兴趣的:(UIButton 解耦)