【发布时间】: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