UIButton+formatter.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 setTitle:title forState:stateType];
  18. [self.titleLabel setFont:[UIFont scaleSize:font]];
  19. [self setImage:image forState:stateType];
  20. [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
  21. }
  22. -(void) setTitle:(NSString*)title textColor:(UIColor*)color font:(CGFloat)font fotState:(UIControlState)stateType
  23. {
  24. [self setTitle:title forState:stateType];
  25. [self setTitleColor:color forState:stateType];
  26. [self.titleLabel setFont:[UIFont scaleSize:font]];
  27. }
  28. -(void)setTitleNormal:(NSString*)title
  29. {
  30. [self setTitle:title forState:UIControlStateNormal];
  31. }
  32. -(void)setTitleSelect:(NSString*)title
  33. {
  34. [self setTitle:title forState:UIControlStateSelected];
  35. }
  36. -(void)target:(id)obj
  37. {
  38. [self addTarget:obj action:NSSelectorFromString(@"btnClick:") forControlEvents:UIControlEventTouchUpInside];
  39. }
  40. -(void)target:(id)obj tag:(NSInteger)tag
  41. {
  42. self.tag = tag;
  43. [self target:obj];
  44. }
  45. @end