// // PdDetailKeyboardInputView.m // FirstLink // // Created by 王孝道 on 15/6/16. // Copyright (c) 2015年 FirstLink. All rights reserved. // #import "PdDetailKeyboardInputView.h" @interface PdDetailKeyboardInputView () @property (nonatomic, strong) UILabel *holderLabel; @end @implementation PdDetailKeyboardInputView @synthesize textView = _textView; @synthesize confirmButton = _confirmButton; - (instancetype)init { self = [super init]; if (self) { self.backgroundColor = UIColorFromRGB(0xf8f8f8); [self initialize]; } return self; } - (void)initialize { [self addSubview:self.textView]; [self addSubview:self.confirmButton]; [self addSubview:self.holderLabel]; } - (void)layoutSubviews { [super layoutSubviews]; CGFloat height = 50; CGFloat btnWidth = 60; self.textView.frame = CGRectMake(15, 10, UISCREENWIDTH - btnWidth - 15, 30); self.holderLabel.frame = CGRectMake(18, 10, CGRectGetWidth(self.textView.bounds), CGRectGetHeight(self.textView.bounds)); CGFloat btnCenterX = CGRectGetMaxX(self.textView.frame) + btnWidth / 2; self.confirmButton.bounds = CGRectMake(0, 0, btnWidth, height); self.confirmButton.center = CGPointMake(btnCenterX, CGRectGetMidY(self.bounds)); } #pragma mark - textView delegate //- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ // NSString *newStr = [textView.text stringByReplacingCharactersInRange:range withString:text]; // NSString *holderString = @""; // // if (newStr.length == 0) { // holderString = self.placeHolder; // } // self.holderLabel.text = holderString; // return YES; //} - (void)textViewDidChange:(UITextView *)textView{ NSString *holderString = @""; if (textView.text.length == 0) { holderString = self.placeHolder; } self.holderLabel.text = holderString; } #pragma mark - getter && setter - (UITextView *)textView { if (_textView == nil) { _textView = [[UITextView alloc]init]; _textView.textColor = [UIColor blackColor]; _textView.font = [UIFont systemFontOfSize:15]; _textView.layer.borderWidth = 0.5; _textView.layer.borderColor = [UIColorFromRGB(0xcccccc) CGColor]; _textView.layer.cornerRadius = 5; _textView.delegate = self; } return _textView; } - (UIButton *)confirmButton { if (_confirmButton == nil) { _confirmButton = [UIButton buttonWithType:UIButtonTypeCustom]; _confirmButton.titleLabel.font = [UIFont systemFontOfSize:14]; [_confirmButton setTitle:@"发送" forState:UIControlStateNormal]; [_confirmButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; } return _confirmButton; } - (UILabel *)holderLabel { if (_holderLabel == nil) { _holderLabel = [[UILabel alloc]init]; _holderLabel.backgroundColor = [UIColor clearColor]; _holderLabel.textAlignment = NSTextAlignmentLeft; _holderLabel.font = [UIFont systemFontOfSize:15]; _holderLabel.textColor = [UIColor blackColor]; _holderLabel.enabled = NO; } return _holderLabel; } - (void)setPlaceHolder:(NSString *)placeHolder { _placeHolder = placeHolder; self.holderLabel.text = placeHolder; } @end