UIButton+formatter.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // UIButtom+formatter.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/16.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "UIButton+formatter.h"
  9. @implementation UIButton(formatter)
  10. - (void) setImage:(UIImage *)image withTitle:(NSString *)title forState:(UIControlState)stateType {
  11. [self setImage:image withTitle:title Font:10 forState:stateType];
  12. }
  13. - (void) setImage:(UIImage *)image withTitle:(NSString *)title Font:(CGFloat)font forState:(UIControlState)stateType{
  14. [self.titleLabel setContentMode:UIViewContentModeCenter];
  15. [self.titleLabel setBackgroundColor:[UIColor clearColor]];
  16. [self setTitleColor:kTitleColor forState:stateType];
  17. // [self setTitleColor:kTitleColor forState:stateType];
  18. [self setTitle:title forState:stateType];
  19. [self.titleLabel setFont:[UIFont scaleSize:font]];
  20. [self setImage:image forState:stateType];
  21. [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
  22. }
  23. -(void) setTitle:(NSString*)title textColor:(UIColor*)color Font:(CGFloat)font fotState:(UIControlState)stateType
  24. {
  25. [self setTitle:title forState:stateType];
  26. [self setTitleColor:color forState:stateType];
  27. [self.titleLabel setFont:[UIFont scaleSize:font]];
  28. }
  29. - (void)setImage:(UIImage *)image withTitle:(NSString*)title textColor:(UIColor*)color Font:(CGFloat)font fotState:(UIControlState)stateType {
  30. [self.titleLabel setContentMode:UIViewContentModeCenter];
  31. [self.titleLabel setBackgroundColor:[UIColor clearColor]];
  32. [self setTitleColor:color forState:stateType];
  33. [self setTitle:title forState:stateType];
  34. [self.titleLabel setFont:[UIFont scaleSize:font]];
  35. [self setImage:image forState:stateType];
  36. [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
  37. }
  38. -(void)setTitleNormal:(NSString*)title
  39. {
  40. [self setTitle:title forState:UIControlStateNormal];
  41. }
  42. -(void)setTitleSelect:(NSString*)title
  43. {
  44. [self setTitle:title forState:UIControlStateSelected];
  45. }
  46. -(void)target:(id)obj
  47. {
  48. [self addTarget:obj action:NSSelectorFromString(@"btnClick:") forControlEvents:UIControlEventTouchUpInside];
  49. }
  50. -(void)target:(id)obj tag:(NSInteger)tag
  51. {
  52. self.tag = tag;
  53. [self target:obj];
  54. }
  55. @end