我正在使用UITextView
,我想刪除UITextview
底部的空格。如何刪除UITextView底部的空格?
0
A
回答
1
我上面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;
2
是這樣的嗎?
textView.text = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
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;
相關問題
- 1. 從UITextView刪除底部空間
- 2. 如何刪除頁面底部頂部e的空格?
- 3. 刪除空行到底部
- 4. CCLabelBMFont對頂部和底部空的空間...如何刪除?
- 5. 如何從輸出底部刪除空格?
- 6. 如何從頁腳底部刪除空格
- 7. MPAndroidChart - 刪除頂部和底部空間
- 8. 如何從JTable底部刪除多餘的空白空間?
- 9. 如何使用NestedScrollView刪除CoordinatorLayout底部的空白空間
- 10. 如何刪除桌子底部的空白空間?
- 11. 如何刪除RadEditor底部的空白空間
- 12. 刪除屏幕底部的空白Android
- 13. 刪除telerik底部的空白RadComboBox
- 14. 刪除博客底部的空白處
- 15. 如何刪除我的網頁底部的大白空間?
- 16. 如何刪除UINavigationBar的邊界底部?
- 17. hightcharts - 如何刪除底部的框
- 18. 如何刪除摺疊工具欄的底部空白處?
- 19. 如何刪除底部\頁腳的WebView白色空間(安卓)
- 20. 如何刪除底部額外的iframe空間?
- 21. 如何刪除底部的多餘空間
- 22. 如何刪除底部的動態內容空間?
- 23. 如何刪除HTML頁面底部的多餘空間?
- 24. 如何從DataGridView控件的底部刪除空行?
- 25. 如何刪除頁面底部的空白(鍍鉻擴展名)?
- 26. 從表格中刪除底部邊框
- 27. 如何刪除表格元素中圖像底部的邊距?
- 28. 如何刪除底部滾動?
- 29. 如何刪除分隔在底部AppBarLayout
- 30. 表中pdfMake.js和分頁符,如何刪除底部空行
我必須寫 - (CGSize)sizeWithFont:(UIFont *)字體constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode; .h文件中的 方法? – PJR
textViewRect.height = textSize.height; 行顯示錯誤 – PJR
不,這是一個NSString實例方法,因此您可以將它包含在代碼中,而不必在界面中聲明它。 –