如何删除UITextView底部的空格?
答
我上面code.try已经更新了它。我有觉得你有欲望的结果..
// Create a size with large height, but matching width to UITextView.
[myTextView setBackgroundColor:[UIColor greenColor]];
CGSize maxSize = CGSizeMake(myTextView.frame.size.width, 20);
// Determine the size needed to display the text - we just need the new height.
CGSize textSize = [myTextView.text sizeWithFont:myTextView.font constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap];
// Set the UITextView's frame to the new height.
CGRect textViewRect = myTextView.frame;
textViewRect.size.height = textSize.height+13;
myTextView.frame = textViewRect;
答
是这样的吗?
textView.text = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
答
我猜想/猜测你想调整一个UITextView很好地容纳文本。如果是的话,我建议你的调查:
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode;
例如:
// Create a size with large height, but matching width to UITextView.
CGSize maxSize = CGSizeMake(myTextView.frame.size.width, 9999);
// Determine the size needed to display the text - we just need the new height.
CGSize textSize = [myTextView.text sizeWithFont:myTextView.font constrainedToSize:maxSize lineBreakMode:UILineBreakModeWordWrap];
// Set the UITextView's frame to the new height.
CGRect textViewRect = myTextView.frame;
textViewRect.size.height = textSize.height;
myTextView.frame = textViewRect;
我必须写 - (CGSize)sizeWithFont:(UIFont *)字体constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode; .h文件中的 方法? – PJR
textViewRect.height = textSize.height; 行显示错误 – PJR
不,这是一个NSString实例方法,因此您可以将它包含在代码中,而不必在界面中声明它。 –