1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- //
- // STTButton.m
- // jiaPeiC
- //
- // Created by apple on 16/6/6.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "STTButton.h"
- @implementation STTButton
- -(instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setTitleColor:contentTextColor forState:UIControlStateNormal];
- [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
- [self.titleLabel setFont:[UIFont systemFontOfSize:Font16]];
- self.titleLabel.numberOfLines = 0;
-
- [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
- }
- return self;
- }
- -(CGRect)imageRectForContentRect:(CGRect)contentRect
- {
- CGFloat hei = self.frame.size.height;
- CGFloat wid = self.frame.size.width;
- CGFloat len = hei < wid ? hei:wid;
- CGFloat ivWH = len*.45;
-
- return CGRectMake( (wid - ivWH)/2, hei* .1, ivWH, hei*.55);
- }
- -(CGRect)titleRectForContentRect:(CGRect)contentRect
- {
- CGFloat hei = self.frame.size.height;
- CGFloat wid = self.frame.size.width;
-
- return CGRectMake( 0, hei * .65, wid, hei*.25);
- }
- -(void)setColorWithSelected:(BOOL)selected
- {
- if (selected) {
- //NSLog(@"yes");
- self.imageView.image = [self.imageView.image tint:defGreen];
- self.titleLabel.textColor = defGreen;
- }else{
- //NSLog(@"no");
- self.imageView.image = [self.imageView.image tint:contentTextColor];
- self.titleLabel.textColor = contentTextColor;
- }
- }
- @end
|