説明なし

PdDetailKeyboardInputView.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // PdDetailKeyboardInputView.m
  3. // FirstLink
  4. //
  5. // Created by 王孝道 on 15/6/16.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "PdDetailKeyboardInputView.h"
  9. @interface PdDetailKeyboardInputView () <UITextViewDelegate>
  10. @property (nonatomic, strong) UILabel *holderLabel;
  11. @end
  12. @implementation PdDetailKeyboardInputView
  13. @synthesize textView = _textView;
  14. @synthesize confirmButton = _confirmButton;
  15. - (instancetype)init
  16. {
  17. self = [super init];
  18. if (self) {
  19. self.backgroundColor = UIColorFromRGB(0xf8f8f8);
  20. [self initialize];
  21. }
  22. return self;
  23. }
  24. - (void)initialize
  25. {
  26. [self addSubview:self.textView];
  27. [self addSubview:self.confirmButton];
  28. [self addSubview:self.holderLabel];
  29. }
  30. - (void)layoutSubviews
  31. {
  32. [super layoutSubviews];
  33. CGFloat height = 50;
  34. CGFloat btnWidth = 60;
  35. self.textView.frame = CGRectMake(15, 10, UISCREENWIDTH - btnWidth - 15, 30);
  36. self.holderLabel.frame = CGRectMake(18, 10, CGRectGetWidth(self.textView.bounds), CGRectGetHeight(self.textView.bounds));
  37. CGFloat btnCenterX = CGRectGetMaxX(self.textView.frame) + btnWidth / 2;
  38. self.confirmButton.bounds = CGRectMake(0, 0, btnWidth, height);
  39. self.confirmButton.center = CGPointMake(btnCenterX, CGRectGetMidY(self.bounds));
  40. }
  41. #pragma mark - textView delegate
  42. //- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
  43. // NSString *newStr = [textView.text stringByReplacingCharactersInRange:range withString:text];
  44. // NSString *holderString = @"";
  45. //
  46. // if (newStr.length == 0) {
  47. // holderString = self.placeHolder;
  48. // }
  49. // self.holderLabel.text = holderString;
  50. // return YES;
  51. //}
  52. - (void)textViewDidChange:(UITextView *)textView{
  53. NSString *holderString = @"";
  54. if (textView.text.length == 0) {
  55. holderString = self.placeHolder;
  56. }
  57. self.holderLabel.text = holderString;
  58. }
  59. #pragma mark - getter && setter
  60. - (UITextView *)textView {
  61. if (_textView == nil) {
  62. _textView = [[UITextView alloc]init];
  63. _textView.textColor = [UIColor blackColor];
  64. _textView.font = [UIFont systemFontOfSize:15];
  65. _textView.layer.borderWidth = 0.5;
  66. _textView.layer.borderColor = [UIColorFromRGB(0xcccccc) CGColor];
  67. _textView.layer.cornerRadius = 5;
  68. _textView.delegate = self;
  69. }
  70. return _textView;
  71. }
  72. - (UIButton *)confirmButton
  73. {
  74. if (_confirmButton == nil) {
  75. _confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
  76. _confirmButton.titleLabel.font = [UIFont systemFontOfSize:14];
  77. [_confirmButton setTitle:@"发送" forState:UIControlStateNormal];
  78. [_confirmButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  79. }
  80. return _confirmButton;
  81. }
  82. - (UILabel *)holderLabel
  83. {
  84. if (_holderLabel == nil) {
  85. _holderLabel = [[UILabel alloc]init];
  86. _holderLabel.backgroundColor = [UIColor clearColor];
  87. _holderLabel.textAlignment = NSTextAlignmentLeft;
  88. _holderLabel.font = [UIFont systemFontOfSize:15];
  89. _holderLabel.textColor = [UIColor blackColor];
  90. _holderLabel.enabled = NO;
  91. }
  92. return _holderLabel;
  93. }
  94. - (void)setPlaceHolder:(NSString *)placeHolder
  95. {
  96. _placeHolder = placeHolder;
  97. self.holderLabel.text = placeHolder;
  98. }
  99. @end