如何在自定义单元格中使用 autoresizingMask 制作 UILabel?
我有一个带有多个标签的自定义 uitableviewcell,我希望其中一些标签能够根据内容(文本)自动调整其框架(宽度)的大小。我不知道如何做到这一点。我尝试设置标签的固定框架并在应用 autoresizingMask 后,但这并不能解决问题。任何 * 指向示例的指针吗?
I have a custom uitableviewcell with several labels and I would like for some of them to autoresize their frame (width) based on the content (text). I am not sure how to accomplish that. I tried to set fixed frame of the label and after apply autoresizingMask, but that doesn't do the trick. Any *pointer to a sample?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想调整标签的框架以适合标签文本,只需调用“
This will fit in multipledimens”即可。
If you want to adjust the frame of a label to fit the labels text, just call
This will fit in both dimensions.
使用以下方法:
size.width 将返回标签中的文本在屏幕上占据的实际宽度。将标签宽度设置为等于文本宽度。
Use the following method:
size.width will return the actual width that the text in the label will occupy on the screen. Set the label width equal to width of text.
如果你只是想让标签适合多行,你必须说:
但是我不确定这是否是你想要的......通常如果内容是文本,那么这就是你想要的想。
If you just want to make so that the label fits in multiple lines, you have to say:
However I'm not sure if this is the one that you want... Usually if the content is text than that'll be what you want.