UITextField
的最大长度以匹配屏幕的宽度?
答案 0 :(得分:3)
您可以分四步完成:
UITextField
UITextField
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *text = textField.text;
text = [text stringByReplacingCharactersInRange:range withString:string];
CGSize textSize = [text sizeWithAttributes:@{NSFontAttributeName:textField.font}];
return textSize.width < textField.bounds.size.width;
}