UILabel自动调整大小和位置
我想绘制具有不同颜色的文本,我找到的唯一方法是将每一段字符串颜色分割成不同的 UILabels,所以目前我有四个 UILabels 一个接一个,比方说,label1,标签2、标签3和标签4。
问题在于每个标签的大小和位置,我还没有找到自动执行此操作的方法。
唯一的方法是:
- 将文本设置在所有标签内
- 询问包含此新文本的所有标签的宽度 使用
- 此新宽度调整所有标签的大小
- 将 label2 移动到 label1.x + label1.width,依此类推
这实际上是iPhone 中唯一的方法是这样做吗?
我来自 Android,每个视图都有一个“wrap_content”属性和“relative_layouts”,您可以在其中定义类似...将 label2 rightOf label1 之类的内容。所以我正在寻找类似的简单且自动的东西,但是是在 iPhone 中。
谢谢!
I want to draw a text with different colors and the only way that I've found for do it is to split every piece of string-color in differents UILabels, so currently now I have four UILabels one after another, lets say, label1, label2, label3 and label4.
The problem with that is with the size and the position of every labels, I've not found an automatic way for do it.
The only way is:
- Set the text inside all the labels
- Ask for the width of all the labels with this new text
- Resize all the labels with this new width
- Move label2 to label1.x + label1.width, and so on
This is really the only way in iPhone for do that?
I came from Android and there is a "wrap_content" property for every view and "relative_layouts" where you can define something like.. put label2 rightOf label1. So I'm looking of something simple and automatic like that, but in iPhone.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的应用程序,您可能需要考虑使用单个
UIWebView
。然后您可以使用 HTML 和 CSS 对其内容进行样式设置。Depending on your application, you might want to consider a single
UIWebView
instead. Then you can style the content of it with HTML and CSS.