2014-08-27 37 views
0

我有一个自定义tableCell工作正常,直到我试图在每个单元格的左侧添加图像。 当在conventView中放置图像时,所有工作都很好,但我不喜欢分隔符在图像中间启动时的情况。自定义UITableViewCell,具有默认图像的布局单元格查看器

我想消除每行左侧的空间,我想放置我的图像,因此单元分隔符将仅显示在单元格内容下,而不是在图像的一部分下,我将这个分离器,用于几个小时,现在我不能证明我的内容..

也是我的模拟器我采取类似10秒,以显示表的内容..

u能帮助我请,我知道它假设是简单的事情,但我不能管理这个工作...

谢谢..

这里是我的自定义的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) 
    } 

} 

回答

0

要修复细胞分离机,您需要使用您的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

除此之外,你可以节省你自己和你的同胞的程序员很多如果您将自定义单元格设计为故事板中的原型单元格,而不是以编程方式布置标签等,则会令人头疼。

+0

我发现汽车的布局非常简单,当它的唯一的自动布局,我喜欢编程,然后使用故事板,任何方式我怎么能消除左侧的差距,我将图像放在contentView? – 2014-08-27 21:39:38

+0

我做错了只是试图在imageViewer中使用构建? – 2014-08-28 13:19:09

相关问题