我正在使用UITextView
,我想删除UITextview
底部的空格。
答案 0 :(得分:2)
这样的东西?
textView.text = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
答案 1 :(得分:1)
我用它更新了上面的code.try.i认为你有欲望的结果..
// 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;
答案 2 :(得分:0)
我假设/猜测您希望调整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;