STTButton.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // STTButton.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/6/6.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "STTButton.h"
  9. @implementation STTButton
  10. -(instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. [self setTitleColor:contentTextColor forState:UIControlStateNormal];
  15. [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
  16. [self.titleLabel setFont:[UIFont systemFontOfSize:Font16]];
  17. self.titleLabel.numberOfLines = 0;
  18. [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
  19. }
  20. return self;
  21. }
  22. -(CGRect)imageRectForContentRect:(CGRect)contentRect
  23. {
  24. CGFloat hei = self.frame.size.height;
  25. CGFloat wid = self.frame.size.width;
  26. CGFloat len = hei < wid ? hei:wid;
  27. CGFloat ivWH = len*.45;
  28. return CGRectMake( (wid - ivWH)/2, hei* .1, ivWH, hei*.55);
  29. }
  30. -(CGRect)titleRectForContentRect:(CGRect)contentRect
  31. {
  32. CGFloat hei = self.frame.size.height;
  33. CGFloat wid = self.frame.size.width;
  34. return CGRectMake( 0, hei * .65, wid, hei*.25);
  35. }
  36. -(void)setColorWithSelected:(BOOL)selected
  37. {
  38. if (selected) {
  39. //NSLog(@"yes");
  40. self.imageView.image = [self.imageView.image tint:defGreen];
  41. self.titleLabel.textColor = defGreen;
  42. }else{
  43. //NSLog(@"no");
  44. self.imageView.image = [self.imageView.image tint:contentTextColor];
  45. self.titleLabel.textColor = contentTextColor;
  46. }
  47. }
  48. @end