前端干货搜集

项目开发过程中遇到的一些细节问题

2016-11-03  本文已影响45人  无神
天道.jpg
- (void)textViewDidChange:(UITextView *)textView{

 //此处编写获取输入内容的逻辑
}

以下方法是编写输入字数显示逻辑的最佳时机:

//控制输入的字符数
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

 NSString *toBeString = [textView.text stringByReplacingCharactersInRange:range withString:text];    NSInteger len = [toBeString length];   
 if (len > kMaxInputCharacterLength) { //如果输入框内容大于kMaxInputCharacterLength则弹出警告               
_messageView.text = [toBeString substringToIndex:kMaxInputCharacterLength];        
NSString *maxLength = [NSString stringWithFormat:@"不能超过%@个字",@(kMaxInputCharacterLength)];       
[MBProgressHUD showWarning:maxLength];       
 return NO ;    
}
    return YES;
}
[self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

makeObjectsPerformSelector:为系统方法比起我们自己手动调用遍历移除方法有更好的性能。

CGRect frame = textField.frame;
CGRect resultFrame = [textField convertRect:frame toView:self.view]; //把当前视图的frame转换到目标视图上
self.editTextFieldBottom = resultFrame.origin.y + kTextFieldHeight;
上一篇下一篇

猜你喜欢

热点阅读