久久久久久久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 消失了)
主站蜘蛛池模板: 亚洲精品一区久久久久久 | 久久99精品久久久97夜夜嗨 | 亚洲精品一区二区三区蜜桃久 | 四虎永久在线精品免费一区二 | 精品久久久久香蕉网 | 草草草草视频 | 免费av观看 | 中文av字幕| 97精品一区二区 | 国产精品久久久久久久久免费高清 | 日韩毛片 | 亚洲天堂一区二区 | 国内精品久久久久久久 | 一区二区免费视频 | 日韩高清国产一区在线 | 日本不卡一区 | 国产真实精品久久二三区 | 在线免费观看成人 | 日韩久久精品视频 | 亚洲综合大片69999 | 欧美女优在线观看 | 日韩免费看视频 | 亚洲视频欧美视频 | 成人免费大片黄在线播放 | 亚洲精品国产成人 | 欧美大片久久久 | 亚洲色图图片 | 久久久久久综合 | 三极网站 | 日韩精品在线网站 | 一区二区三区视频在线观看 | 欧产日产国产精品99 | 男女羞羞视频大全 | 亚洲成人一二三 | 一区二区三区国产好 | 国产 欧美 日韩 一区 | 天天艹日日干 | 人人射人人 | 精品国产欧美在线 | 国产亚洲精品久久午夜玫瑰园 | 国产黄色免费网站 |