久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在具有多行的 UILabel 上自動收縮

Autoshrink on a UILabel with multiple lines(在具有多行的 UILabel 上自動收縮)
本文介紹了在具有多行的 UILabel 上自動收縮的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

是否可以在 UILabel 的多行上同時使用 autoshrink 屬性?例如,2 行可用的大文本.

Is it possible to use the autoshrink property in conjunction on multiple lines on a UILabel? for example, the large text size possible on 2 available lines.

推薦答案

這些人找到了解決方案:

These people found a solution:

http://www.11pixel.com/blog/28/resize-multi-line-text-to-fit-uilabel-on-iphone/

他們的解決方案如下:

int maxDesiredFontSize = 28;
int minFontSize = 10;
CGFloat labelWidth = 260.0f;
CGFloat labelRequiredHeight = 180.0f;
//Create a string with the text we want to display.
self.ourText = @"This is your variable-length string. Assign it any way you want!";

/* This is where we define the ideal font that the Label wants to use.
   Use the font you want to use and the largest font size you want to use. */
UIFont *font = [UIFont fontWithName:@"Marker Felt" size:maxDesiredFontSize];

int i;
/* Time to calculate the needed font size.
   This for loop starts at the largest font size, and decreases by two point sizes (i=i-2)
   Until it either hits a size that will fit or hits the minimum size we want to allow (i > 10) */
for(i = maxDesiredFontSize; i > minFontSize; i=i-2)
{
    // Set the new font size.
    font = [font fontWithSize:i];
    // You can log the size you're trying: NSLog(@"Trying size: %u", i);

    /* This step is important: We make a constraint box 
       using only the fixed WIDTH of the UILabel. The height will
       be checked later. */ 
    CGSize constraintSize = CGSizeMake(labelWidth, MAXFLOAT);

    // This step checks how tall the label would be with the desired font.
    CGSize labelSize = [self.ourText sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

    /* Here is where you use the height requirement!
       Set the value in the if statement to the height of your UILabel
       If the label fits into your required height, it will break the loop
       and use that font size. */
    if(labelSize.height <= labelRequiredHeight)
        break;
}
// You can see what size the function is using by outputting: NSLog(@"Best size is: %u", i);

// Set the UILabel's font to the newly adjusted font.
msg.font = font;

// Put the text into the UILabel outlet variable.
msg.text = self.ourText;

為了讓它工作,必須在界面構建器中將 IBOutlet 分配給 UILabel.

In order to get this working, a IBOutlet must be assigned in the interface builder to the UILabel.

"IBOutlet UILabel *msg;"

"IBOutlet UILabel *msg;"

所有的優點都是 11 像素的人.

All the merit is of the people at 11pixel.

這篇關于在具有多行的 UILabel 上自動收縮的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Using Instruments to test an iOS app without having source code to the application(在沒有應用程序源代碼的情況下使用 Instruments 測試 iOS 應用程序)
KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動運行/壓力測試 iOS 應用程序以找出罕見 UI 錯誤的原因?)
Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態和動態單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級到 Xcode 4.5 后,iOS 5 SDK 消失了)
主站蜘蛛池模板: 国产欧美精品一区二区色综合朱莉 | 亚洲国产精品一区在线观看 | 玖操| 最新高清无码专区 | 国产三级一区二区 | h视频在线免费 | 999久久精品| 91精品国产色综合久久不卡98 | 日韩免费一区二区 | 亚州精品天堂中文字幕 | 精品亚洲一区二区三区 | 欧美一区二区三区 | 草久网 | 欧美极品在线播放 | 国产一区二区久久 | 涩涩视频网站在线观看 | 色天天综合 | 中文精品视频 | 国产高清视频在线观看 | 免费精品一区 | 免费欧美视频 | 国产一区二区黑人欧美xxxx | 中文字幕国产视频 | 欧美在线观看一区二区 | 欧美一区二区另类 | 亚洲一区二区中文字幕 | 亚洲性爰 | 久久久这里都是精品 | 情侣酒店偷拍一区二区在线播放 | 色婷婷综合网站 | 色综合中文 | 亚洲精品区 | 91精品国产乱码久久久 | 久久久久久久久91 | 亚洲欧美日韩在线不卡 | 精品中文字幕视频 | 久久精品亚洲 | 日批免费看 | 精品一二区| 亚洲第一天堂 | 国产精品1区|