iOS AILinkBleSDK - 蓝牙SDK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UIButton+WZAdd.m 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // UIButton+WZAdd.m
  3. // 常用UI控件封装
  4. //
  5. // Created by iot_iMac on 2018/6/21.
  6. // Copyright © 2018年 iot_iMac. All rights reserved.
  7. //
  8. #import "UIButton+WZAdd.h"
  9. @implementation UIButton (WZAdd)
  10. /*
  11. * 注意:如果needRoundCorner=YES,则必须设置frame的height值,否则无法实现圆角
  12. */
  13. + (UIButton *)createWithFrame:(CGRect)frame bgColor:(UIColor *)bgColor font:(UIFont *)font norTitle:(NSString *)norTitle norTitleColor:(UIColor *)norTitleColor norImage:(UIImage *)norImage borderColor:(UIColor *)borderColor needRoundCorner:(BOOL)needRoundCorner target:(id)target action:(SEL)action {
  14. //这3项必须有值
  15. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  16. btn.frame = frame;
  17. btn.titleLabel.textAlignment = NSTextAlignmentCenter;
  18. btn.titleLabel.numberOfLines = 0;
  19. btn.titleLabel.adjustsFontSizeToFitWidth = YES;
  20. //以下各项均可为nil
  21. if (font) {
  22. btn.titleLabel.font = font;
  23. }
  24. if (bgColor) {
  25. [btn setBackgroundColor:bgColor];
  26. }
  27. if (norTitle) {
  28. [btn setTitle:norTitle forState:UIControlStateNormal];
  29. }
  30. if (norTitleColor) {
  31. [btn setTitleColor:norTitleColor forState:(UIControlStateNormal)];
  32. }
  33. if (norImage) {
  34. [btn setImage:norImage forState:UIControlStateNormal];
  35. }
  36. if (borderColor) {
  37. btn.layer.borderColor = borderColor.CGColor;
  38. btn.layer.borderWidth = 1;
  39. }
  40. if (needRoundCorner) {
  41. btn.layer.cornerRadius = btn.bounds.size.height/2;
  42. btn.layer.masksToBounds = YES; //防止设置了图片,不能显示圆角问题
  43. }
  44. if (action) { //target可为nil,action不可为nil
  45. [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  46. }
  47. return btn;
  48. }
  49. @end