[英]Iphone: How do I add a text view that the font size decreases to fit text view size when needed to
我試圖做一個UITextView
,其中字體大小被調整為適合文本視圖的大小。 例如,如果您鍵入很多文本,並且將要填滿文本視圖,則文本會變小。
在界面構建器中,您可以調整文本視圖的屬性。 確保選擇自動收縮,將最小字體大小調整為.2(或任意大小)(縮放)。 每次鍵入時,它都會縮小並適合文本視圖。
所有這些都可以在屬性檢查器下找到。
定義您想要字體的最大大小。 我通常將其放在我的.h文件中
然后,在將文本添加到UITextView的.m文件中,您將放置以下內容:
myTextView.text = @"Some long string that will be in the UITextView";
myTextView.font = [UIFont systemFontOfSize:kDefaultFontSize];
//在此處設置文本調整大小
if (myTextView.contentSize.height > myTextView.frame.size.height)
{
int fontIncrement = 1;
while (myTextView.contentSize.height > myTextView.frame.size.height)
{
myTextView.font = [UIFont systemFontOfSize:kDefaultFontSize-fontIncrement];
fontIncrement++;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.