TRButton.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // TRButton.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/12.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "TRButton.h"
  9. @interface TRButton()
  10. {
  11. /**用于使按钮的图片,每次点击都能旋转。
  12. */
  13. NSInteger repeat;
  14. }
  15. @end
  16. @implementation TRButton
  17. -(id)initWithFrame:(CGRect)frame{
  18. self = [super initWithFrame:frame];
  19. // CGFloat wid = frame.size.width;
  20. // CGFloat hei = frame.size.height;
  21. if (self) {
  22. self.backgroundColor = [UIColor whiteColor];
  23. self.titleLabel.font = [UIFont scaleSize:14];
  24. self.titleLabel.textAlignment = NSTextAlignmentCenter;
  25. [self setTitleColor:kTitleColor forState:UIControlStateNormal];
  26. [self setImage:[UIImage imageNamed:@"location_more_arrow"] forState:UIControlStateNormal];
  27. self.layer.borderWidth = 1;
  28. self.layer.borderColor = KlineColor.CGColor;
  29. self.imageView.contentMode = UIViewContentModeScaleAspectFit;
  30. repeat =1 ;
  31. }
  32. return self;
  33. }
  34. -(CGRect)titleRectForContentRect:(CGRect)contentRect
  35. {
  36. CGFloat w = self.width;
  37. CGFloat h = self.height;
  38. return CGRectMake(0, 0, w*.7, h);
  39. }
  40. -(CGRect)imageRectForContentRect:(CGRect)contentRect
  41. {
  42. CGFloat w = self.width;
  43. CGFloat h = self.height;
  44. CGFloat len = 25;
  45. if ( w*.3 > len) {
  46. return CGRectMake(w*.7, 0, len, h);
  47. }
  48. return CGRectMake( w*.7,0,w*.25, h);
  49. }
  50. -(void)makeAnimate{
  51. [UIView animateWithDuration:.3 animations:^{
  52. self.imageView.transform = CGAffineTransformMakeRotation( M_PI * (repeat++));
  53. }];
  54. }
  55. -(void)setImgN:(NSString *)imgN
  56. {
  57. [self setImage:[UIImage imageNamed:imgN] forState:UIControlStateNormal];
  58. }
  59. @end