iOS UILabel 格式提示
有人对在 iOS 中使用标签有任何提示或建议吗?我是一名学习在 iOS 上进行开发的新手,来自 .NET 世界,发现在我正在设计的自定义表格单元中实现我需要的外观非常困难。
基本上我有一个带有两个标签的自定义表格单元格。第一个用于标题,第二个用于副标题。我希望我的标题标签最多包含两行文本并截断较长文本的尾部。对于我的字幕标签,我需要 3 行文本。我的标题标签将是粗体,我的副标题标签将使用小一级的字体。
我唯一困扰的是标签高度。如何在 XCode 中放置标签,以便它们最多容纳两行文本(并优雅地处理单行文本)并对我的字幕标签执行相同的操作。
可能有一个简单的解决方案,但我完全想念它。我无法相信删除最基本的 UI 组件的简单行为在 iOS 中会如此复杂。如果可以避免的话,我不想做任何黑客行为(即在单元格中删除 UI 视图等)。
任何帮助将不胜感激。
Does anyone have any tips or suggestions for working with labels in iOS? I am a newbie learning to develop on iOS and come from .NET world and find it extremely hard to achieve the look I need in a custom table cell I am designing.
Basically I have a custom table cell that has two labels. One for title and second one for sub title. I want my title label to hold at most two lines of text and truncate tail of longer text. For my subtitle label I want 3 lines of text. My title label will be bold and my subtitle label will have one level smaller fonts.
The only thing I am struggling with is the label heights. How to drop labels in XCode so that they accomodate two lines of text at most (and handle single lines of text gracefully) and do the same for my subtitle label.
There may be a simple solution to this but I am missing it completely. I cannot believe a simple act of dropping the most basic UI component can be so complex in iOS. I don't want to do any hacks (i.e. drop UI Views in the cell etc) if I can avoid it.
Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一些教程可以帮助您自定义 UITableViewCells:
http://useyourloaf.com/blog/2011/2/28/speeding-up-table-view-cell-loading-with-uinib.html
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
希望有帮助
Here's a couple of tutorials that may help you with custom UITableViewCells:
http://useyourloaf.com/blog/2011/2/28/speeding-up-table-view-cell-loading-with-uinib.html
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
Hope that helps
您可能想查看
UITableViewCell
上的默认UILabel
。它们分别是textLabel
和detailTextLabel
。 此处查找相关 Apple 文档。You might want to check out the default
UILabel
s onUITableViewCell
. They aretextLabel
anddetailTextLabel
respectively. Find the relevant Apple docs here.