TCTextAddView.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // TCTextAddView.m
  3. // DeviceManageIOSApp
  4. //
  5. // Created by rushanting on 2017/5/18.
  6. // Copyright © 2017年 tencent. All rights reserved.
  7. //
  8. #import "TCTextAddView.h"
  9. //#import "UIView+AdditionsX12.h"
  10. #import "ColorMacro.h"
  11. @implementation TCTextAddView
  12. {
  13. UILabel* _titleLabel;
  14. UIButton* _textAddButton;
  15. }
  16. - (id)initWithFrame:(CGRect)frame
  17. {
  18. if (self = [super initWithFrame:frame]) {
  19. _titleLabel = [UILabel new];
  20. _titleLabel.textColor = UIColorFromRGB(0x777777);
  21. _titleLabel.textAlignment = NSTextAlignmentCenter;
  22. _titleLabel.text = YZMsg(@"文字效果");
  23. _textAddButton = [UIButton new];
  24. [_textAddButton setImage:[UIImage imageNamed:@"text_add"] forState:UIControlStateNormal];
  25. _textAddButton.backgroundColor = UIColorFromRGB(0x181818);
  26. [_textAddButton setTitle:YZMsg(@"添加文字") forState:UIControlStateNormal];
  27. _textAddButton.titleLabel.font = [UIFont systemFontOfSize:16];
  28. _textAddButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
  29. [_textAddButton addTarget:self action:@selector(onTextAddBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
  30. _textAddButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
  31. [self addSubview:_titleLabel];
  32. [self addSubview:_textAddButton];
  33. }
  34. return self;
  35. }
  36. - (void)layoutSubviews
  37. {
  38. [super layoutSubviews];
  39. _titleLabel.frame = CGRectMake(0, 0, self.width, 14);
  40. _textAddButton.frame = CGRectMake(15, _titleLabel.bottom + 25, self.width - 30, 50);
  41. }
  42. - (void)setEdited:(BOOL)isEdited
  43. {
  44. if (!isEdited) {
  45. [_textAddButton setImage:[UIImage imageNamed:@"text_add"] forState:UIControlStateNormal];
  46. [_textAddButton setTitle:YZMsg(@"添加文字") forState:UIControlStateNormal];
  47. }
  48. else {
  49. [_textAddButton setImage:[UIImage imageNamed:@"type"] forState:UIControlStateNormal];
  50. [_textAddButton setTitle:YZMsg(@"编辑文字") forState:UIControlStateNormal];
  51. }
  52. }
  53. - (void)onTextAddBtnClicked:(UIButton*)sender
  54. {
  55. [self.delegate onAddTextBtnClicked];
  56. }
  57. @end