|
//
// blueButton.m
// ThePaperDemo
//
// Created by scar1900 on 14/11/27.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "blueButton.h"
@implementation blueButton
- (id)initWithFrame:(CGRect)frame withColor:(UIColor*)color{
self = [super initWithFrame:frame];
if (self) {
self.layer.cornerRadius = 4.f;
self.clipsToBounds = YES;
if (color) {
[self setBackgroundImage:imageWithUIColor(color)
forState:UIControlStateNormal];
}else {
[self setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR])
forState:UIControlStateNormal];
}
[self setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONSELECTBACK])
forState:UIControlStateHighlighted];
[self setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONDISABLEBACK])
forState:UIControlStateDisabled];
[self addSubview:self.shareImageView];
[self addSubview:self.textLabel];
}
return self;
}
- (UIImageView*)shareImageView {
if (!_shareImageView) {
_shareImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
_shareImageView.backgroundColor = [UIColor clearColor];
}
return _shareImageView;
}
- (UILabel*)textLabel {
if (!_textLabel) {
_textLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_textLabel.backgroundColor = [UIColor clearColor];
_textLabel.textAlignment = NSTextAlignmentLeft;
_textLabel.textColor = [UIColor whiteColor];
}
return _textLabel;
}
- (void)layoutSubviews {
CGSize size = self.shareImageView.image.size;
if (self.bounds.size.width > 0) {
if (size.width == size.height) {
// self.shareImageView.frame = CGRectMake(15/2, CGRectGetHeight(self.bounds)/2-size.height/2, size.width , size.height);
[self.shareImageView remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left).offset(15/2);
make.centerY.equalTo(self.centerY);
make.width.equalTo(@(size.width));
make.height.equalTo(@(size.height));
}];
}else {
// self.shareImageView.frame = CGRectMake(10, CGRectGetHeight(self.bounds)/2-size.height/2, size.width , size.height);
[self.shareImageView remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left).offset(10);
make.centerY.equalTo(self.centerY);
make.width.equalTo(@(size.width));
make.height.equalTo(@(size.height));
}];
}
}else {
[self.shareImageView remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left).offset(10);
make.right.equalTo(self.right);
make.width.equalTo(@0);
make.height.equalTo(@0);
}];
}
// self.textLabel.frame = CGRectMake(CGRectGetMaxX(self.shareImageView.frame)+5, 0, 125/2, 30);
CGFloat fontSize = 11;
if (isPad) {
fontSize = 15;
}
self.textLabel.font = appFont(fontSize, NO);
[self.textLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.shareImageView.right).offset(5);
make.top.equalTo(self.top);
make.width.equalTo(@125);
make.bottom.equalTo(self.bottom);
}];
[super layoutSubviews];
}
@end
|