【问题标题】:custom UITableViewCell, layout cell with default imageViewer自定义 UITableViewCell,带有默认 imageViewer 的布局单元
【发布时间】:2014-08-27 19:52:34
【问题描述】:

我有一个工作正常的自定义 tableCell,直到我尝试在每个单元格的左侧添加一个图像。 将图像放在 conventView 中时一切正常,但我不喜欢分隔符从图像中间开始。

我想消除每一行左边的空间,我想把我的图像放在那里,所以单元格分隔符只会显示在单元格内容下方,而不是图像的一部分下方,我正在使用这个分隔符几个小时,现在我无法显示我的内容..

我的模拟器也花了大约 10 秒来显示表格内容..

你能帮帮我吗,我知道这很简单,但我无法让它工作......

谢谢你..

这是我的自定义 TableCell

import UIKit

class TableCellMessages: UITableViewCell {
    var labUerName = UILabel();
    var labMessage = UILabel();
    var labTime    = UILabel();
    var labRead    = UILabel();


    override func awakeFromNib() {
        super.awakeFromNib()

        self.imageView.clipsToBounds = true
        self.imageView.layer.cornerRadius = 22;
        self.imageView.contentMode = UIViewContentMode.ScaleAspectFill
//        self.imageView.autoresizingMask = UIViewAutoresizing.None

        var currentFont:UIFont = labUerName.font
        labUerName.font = UIFont.boldSystemFontOfSize(currentFont.pointSize);

        labUerName.setTranslatesAutoresizingMaskIntoConstraints(false)
        labMessage.setTranslatesAutoresizingMaskIntoConstraints(false)
        labTime.setTranslatesAutoresizingMaskIntoConstraints(false)
        labRead.setTranslatesAutoresizingMaskIntoConstraints(false)

        contentView.addSubview(labUerName)
        contentView.addSubview(labMessage)
        contentView.addSubview(labTime)
        contentView.addSubview(labRead)


        //Set layout
        var viewsDict = Dictionary <String, UIView>()
        viewsDict["username"] = labUerName;
        viewsDict["message"] = labMessage;
        viewsDict["time"] = labTime;
        viewsDict["read"] = labRead;

        contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[username]-1-[message]", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDict))
        contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[time]-1-[read]", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDict))
        contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[username]-[time]-|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDict))
        contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[message]-[read]-|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDict))

    }

    override func layoutSubviews() {
        super.layoutSubviews()

        var x = self.frame.origin.x;
        var y = self.frame.origin.y;
        var width = self.frame.width;
        var height = self.frame.height;

        self.imageView.frame = CGRectMake(x, y, height, height);
        self.contentView.frame = CGRectMake(x + height, y, width - height , height)
    }

}

【问题讨论】:

    标签: ios uitableview swift


    【解决方案1】:

    要修复单元格分隔符,您需要使用 UITableView 上的 separatorInset 属性,您很可能在视图控制器中引用了该属性:

    self.tableView.separatorInset = UIEdgeInsets(0, 0, 0, 0)

    https://developer.apple.com/library/prerelease/iOS/documentation/UIKit/Reference/UITableView_Class/index.html#//apple_ref/occ/instp/UITableView/separatorInset

    除此之外,如果您将自定义单元格设计为情节提要中的原型单元格,而不是以编程方式布置标签等,那么您和您的其他程序员会省去很多麻烦。

    【讨论】:

    • 我发现自动布局很容易,当它唯一的自动布局时,我更喜欢编程然后使用情节提要,无论如何我怎样才能消除左边的间隙,我将把图像放在什么内容视图?
    • 我只是尝试使用 imageViewer 中的构建做错了吗?
    猜你喜欢
    • 1970-01-01
    • 2011-01-15
    • 1970-01-01
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多