HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何截断UITableView Cell TextLabel中的文本,以便它不会隐藏DetailTextLabel?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个电话费率列表,textLabel是国家/地区,detailTextLabel是我必须显示的费率.

对于某些字符串,textLabel太长并且detailTextLabel变为隐藏状态.是否有设置自动调整文本…如果它太长了?

以下是中非共和国(移动)有此问题的示例:

解决方法

在布局具有UITableViewCellStyle.Value1样式的单元格时,标题标签似乎优先,并将详细标签推出视图.解决方案可能是继承UITableViewCell并覆盖其layoutSubviews():
override func layoutSubviews() {
        super.layoutSubviews()

        if let detail = self.detailTextLabel {
            // this will do the actual layout of the detail 
            // label's text,so you can get its width
            detail.sizeToFit() 

            // you might want to find a cLever way to calculate this
            // instead of assigning a literal
            let rightMargin: CGFloat = 16

            // adjust the detail's frame
            let detailWidth = rightMargin + detail.frame.size.width
            detail.frame.origin.x = self.frame.size.width - detailWidth
            detail.frame.size.width = detailWidth
            detail.textAlignment = .Left

            // Now truncate the title label        
            if let text = self.textLabel {
                if text.frame.origin.x + text.frame.size.width > self.frame.width - detailWidth {
                    text.frame.size.width = self.frame.width - detailWidth - text.frame.origin.x
                }
            }
        }
    }

请注意,尽管detail.textAlignment = .Left我们虑了细节的宽度,实际文本最终与右侧对齐.

大佬总结

以上是大佬教程为你收集整理的ios – 如何截断UITableView Cell TextLabel中的文本,以便它不会隐藏DetailTextLabel?全部内容,希望文章能够帮你解决ios – 如何截断UITableView Cell TextLabel中的文本,以便它不会隐藏DetailTextLabel?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。