Daha iyi kullanım otomatik düzen, her iki yönde çalışmayı uygulamayı yapacak.
Ayrıca, uygulamanızda, her hücre için cellForRowAtIndexPath yöntemi çağrıldığında bgView her seferinde oluşturulur, bu nedenle bgView'ın yalnızca bgView'ı oluşturmaktan daha iyi olup olmadığını kontrol edin. Lütfen aşağıdaki koda bakın.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CellID", forIndexPath: indexPath)
cell.backgroundColor = UIColor.clearColor()
if cell.backgroundView == nil {
let leftView = UIView()
let rightView = UIView()
rightView.backgroundColor = UIColor.redColor()
leftView.backgroundColor = UIColor.yellowColor()
cell.backgroundView = UIView()
cell.backgroundView?.addSubview(leftView)
cell.backgroundView?.addSubview(rightView)
leftView.translatesAutoresizingMaskIntoConstraints = false;
rightView.translatesAutoresizingMaskIntoConstraints = false;
let viewDict = ["leftView":leftView, "rightView":rightView]
cell.backgroundView!.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[leftView]-0-|", options: [], metrics: nil, views: viewDict))
cell.backgroundView!.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[rightView]-0-|", options: [], metrics: nil, views: viewDict))
cell.backgroundView!.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[leftView]-0-[rightView(==leftView)]-0-|", options: [], metrics: nil, views: viewDict))
}
cell.textLabel?.text = "dsfsdkjfh fkjhsdkjfhs kdfksdhfk sdf";
return cell
}
Cell.contentView.frame.size.width dosyasını deneyin. –
yaptı. Bu 'cell.frame.size.width' – DDR