简体   繁体   English

如何自动缩小标签中多行文字?

[英]How to autoshrink text with multiple lines in a label?

I have some labels in my app that displays the questions in my quiz-game! 我的应用程序中有一些标签,可以在问答游戏中显示问题! Some questions are alot longer than others, and they does not fit in the label(they get cut in the end and ends with...) How do I make them fit in the label(with smaller letters) without changing the size of the letters in the shorter questions? 有些问题比其他问题长很多,并且它们不适合标签(它们被切开并以...结尾)。如何在不改变标签大小的情况下使它们适合标签(带有较小的字母)字母在较短的问题?

Just check length of your question, if length is fine then do nothing and if length will increase then change font size. 只需检查您的问题的长度,如果长度合适,则不执行任何操作,如果长度增加,则更改字体大小。

or you can use this according to your label height and width. 或者您可以根据标签的高度和宽度来使用它。

CGSize constraint = CGSizeMake(132, 2000.0f);
CGSize size = [text sizeWithFont: [UIFont fontWithName:@"Verdana" size:13]
               constrainedToSize:constraint
                   lineBreakMode:UILineBreakModeWordWrap];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM