我正在开发一个应用程序,其中需要根据要显示的文本自动调整文本区域的大小。
首先,我不确定我是否应该使用UILabel
(逻辑上是显示静态文本的最佳选择,就我而言)或UITextView
.
我希望如何使用它?
我想简单地用文本初始化我的标签或文本视图。
相反,我首先定义框架,然后将文本限制在该区域。
如果您能提出正确的解决方案,那将是一个很大的帮助。
我浏览了文档和其他参考资料,但没有找到太多可以帮助我的东西,否则我可能会忽略它。
The sizeToFit
方法效果很好。
我做了以下。
UILabel *testLabel =[[UILabel alloc] initWithFrame:CGRectMake(6,3, 262,20 )]; // RectMake(xPos,yPos,Max Width I want, is just a container value);
NSString * test=@"this is test this is test inthis is test ininthis is test inthis is test inthis is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...this is test in uilabel ...";
testLabel.text = test;
testLabel.numberOfLines = 0; //will wrap text in new line
[testLabel sizeToFit];
[self.view addSubview:testLabel];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)