UIButton+ex.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // UIButton+ex.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/13.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "UIButton+ex.h"
  9. @implementation UIButton (ex)
  10. -(void)setTitleUnderImgWithTitle:(NSString *)title TitleColor:(UIColor *)color Image:(UIImage *)image label:(UILabel *)topLab{
  11. CGFloat width = self.frame.size.width;
  12. CGFloat height = self.frame.size.height/10;
  13. CGRect topFrame = CGRectMake(width/2-height*5/2, height*1.5, height*5, height*5);
  14. if (image) {
  15. //图片+文字
  16. UIImageView * imgV = [[UIImageView alloc]initWithFrame:topFrame];
  17. imgV.image = image;
  18. [self addSubview:imgV];
  19. // self.layer.borderWidth = .5f;
  20. // self.layer.borderColor = [UIColor colorWithRed:230/255.0f green:230/255.0f blue:230/255.0f alpha:1].CGColor;
  21. }else{
  22. //lable+文字
  23. topLab.frame = topFrame;
  24. topLab.font = [UIFont systemFontOfSize:[self scaleFontSize:16]];
  25. topLab.textColor = [UIColor darkGrayColor];
  26. topLab.textAlignment = NSTextAlignmentCenter;
  27. // topLab.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
  28. topLab.layer.borderWidth = .5f;
  29. topLab.layer.borderColor = [UIColor lightGrayColor].CGColor;//colorWithRed:230/255.0f green:230/255.0f blue:230/255.0f alpha:1
  30. topLab.layer.masksToBounds = YES;
  31. topLab.layer.cornerRadius = 5;
  32. [self addSubview:topLab];
  33. // UILabel * Vline = [[UILabel alloc]initWithFrame:CGRectMake(width-1, height*2, 1, height*6)];
  34. // Vline.backgroundColor = RGB_COLOR(230, 230, 230);
  35. // [self addSubview:Vline];
  36. }
  37. UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, height*6.5, width, height*3)];
  38. lab.text = title;
  39. lab.textAlignment = NSTextAlignmentCenter;
  40. lab.textColor = [UIColor darkGrayColor];
  41. lab.font = [UIFont systemFontOfSize:[self scaleFontSize:14]];
  42. lab.numberOfLines = 2;//
  43. if (topLab) {
  44. lab.textColor = [UIColor grayColor];
  45. }
  46. [self addSubview:lab];
  47. }
  48. -(void)setTitle:(NSString*)title textColor:(UIColor*)color font:(CGFloat)font fotState:(UIControlState)stateType
  49. {
  50. [self setTitle:title forState:stateType];
  51. [self setTitleColor:color forState:stateType];
  52. [self.titleLabel setFont:[UIFont systemFontOfSize:font]];
  53. }
  54. -(CGFloat)scaleFontSize:(CGFloat)size{
  55. if (kSize.width < 414) {
  56. return size-1;
  57. }
  58. return size;
  59. }
  60. -(void)borderColor:(UIColor *)color width:(CGFloat)wid cornorRadios:(CGFloat)cornor
  61. {
  62. self.layer.masksToBounds = YES;
  63. self.layer.borderWidth = wid;
  64. self.layer.cornerRadius = cornor;
  65. self.layer.borderColor = color.CGColor;
  66. }
  67. @end