如何删除 UITextView 底部的空格?

发布于 2024-12-07 22:49:45 字数 74 浏览 1 评论 0原文

我正在使用 UITextView 并且我想删除 UITextview 底部的空格。

i am using UITextView and i want to remove spaces in the bottom of the UITextview.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扎心 2024-12-14 22:49:45

像这样的东西吗?

textView.text = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]];

Something like this?

textView.text = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

海的爱人是光 2024-12-14 22:49:45

我已经更新了上面的代码。尝试一下。我认为你得到了想要的结果..

// 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;

I have updated above code.try with it.i think you got desire result..

// 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;
戴着白色围巾的女孩 2024-12-14 22:49:45

我假设/猜测您希望调整 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;

I'm assuming/guessing you wish to resize a UITextView to accommodate the text nicely. If so, I suggest you investigate:

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode;

For example:

// 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文