显示格式化 NSString 的最佳方式? UILabel 失败
显示格式化 NSString 的最佳方式是什么?我正在尝试格式化应用程序上多项选择题的选项。
choices1 = [NSString stringWithFormat:@"\n\n Blue \n\n"
"Yellow \n\n"
"Red \n\n"
"Orange \n\n"];
我想在 iPhone 屏幕上显示它。我尝试使用 UILabel 但它无法识别新行字符。 (虽然它打印了这些词)。
应该是这样的:
蓝色
黄色
红色
橙色
想法?谢谢。
What is the best way to display a formatted NSString? I'm trying to format the choices for a multiple choice question on an app.
choices1 = [NSString stringWithFormat:@"\n\n Blue \n\n"
"Yellow \n\n"
"Red \n\n"
"Orange \n\n"];
I want to display that on the iPhone screen. I tried using UILabel but it doesn't recognize the new line characters. (It prints the words though).
should look like this:
Blue
Yellow
Red
Orange
Thoughts? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
UILabel默认为单行显示。如果您需要多行,请将
numberOfLines
设置为 0(无限行),或者设置为您想要限制标签的任意行数。UILabel defaults to single-line display. If you want multiple lines, set
numberOfLines
to 0, for unlimited lines, or to whatever number of lines you want to cap the label at.像这样更改 UILabel 的一些属性:
享受编码..
Change some properties of UILabel like this :
Enjoy coding..
设置
numberOfLines = 4
和UILabel = 300
的高度(您可以检查字符串是否适合这个高度。如果不适合增加高度)。Set
numberOfLines = 4
and height ofUILabel = 300
(You can check if string fits in this height. If not increase the height).您最好使用 4 个 UILabels,并将标签准确地放置在屏幕上您想要的位置,而不是使用 C 语法来分隔您的选择。那么你就不必担心像这样将它们分开。当您以图形方式设计界面时,修改和查看正在执行的操作也更加容易。
Rather than spacing your choices with C syntax, you'd be better off to use 4 UILabels and just position the labels on screen exactly where you'd like them. Then you don't have to be concerned with spacing them all apart like that. It's also much easier to modify and see what you're doing when you're designing your interface graphically.