UIBarButtonItem+Extension.m 953 B

1234567891011121314151617181920212223242526
  1. //
  2. // UIBarButtonItem+Extension.m
  3. // 黑马微博2期
  4. //
  5. // Created by apple on 14-10-7.
  6. // Copyright (c) 2014年 heima. All rights reserved.
  7. //
  8. #import "UIBarButtonItem+Extension.h"
  9. @implementation UIBarButtonItem (Extension)
  10. + (UIBarButtonItem *)itemWithTarget:(id)target action:(SEL)action image:(NSString *)image highImage:(NSString *)highImage
  11. {
  12. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  13. [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  14. // 设置图片
  15. [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
  16. [btn setImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
  17. // 设置尺寸
  18. btn.size = CGSizeMake(btn.currentImage.size.width+20, btn.currentImage.size.height+16);
  19. btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  20. return [[UIBarButtonItem alloc] initWithCustomView:btn];
  21. }
  22. @end