封装一个button上带图片的,图片在上,文字在下的按钮

#import "CJShoppingDetailButton.h"

@implementation CJShoppingDetailButton

- (void)layoutSubviews{

[super layoutSubviews];

CGSize imageSize = self.imageView.image.size;

CGSize titleLabelSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font maxSize:CGSizeMake(self.width, self.height)];

CGFloat imageViewY = (self.height - imageSize.height - titleLabelSize.height) / 3.f;

CGFloat imageViewX = (self.width - imageSize.width) / 2.f;

self.imageView.frame = CGRectMake(imageViewX, imageViewY, imageSize.width, imageSize.height);

CGFloat titleLabelX = (self.width - titleLabelSize.width) / 2.f;

self.titleLabel.frame = CGRectMake(titleLabelX, self.imageView.bottom + imageViewY, titleLabelSize.width, titleLabelSize.height);

}

@end

#import <UIKit/UIKit.h>

@interface CJShoppingDetailButton : UIButton

@end

上一篇:【云栖号案例 | 互联网】智启蓝墨通过块存储提升云班课核心业务性能


下一篇:阿里开源富容器引擎 PouchContainer 的 network 连接机制