When you post code, you should Paste and Match style to avoid all the extra blank lines.
What is test detail ? Is it a func ?
cellView has no frame defined.
UIView doc states:
init(frame:) - It is recommended that you implement this method. You can also implement custom initialization methods in addition to, or instead of, this method.
So you should change line 8 in something like
Code Block let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 40)) |
Code Block class customCell: UITableViewCell { |
|
let testdetails = testdetail() |
|
var count = 0 |
|
let cellView: UIView = { |
let view = UIView() |
view.backgroundColor = .white |
return view |
}() |
|
let imageOrderForCell: UIImageView = { |
let iv = UIImageView() |
iv.contentMode = .scaleAspectFit |
iv.image = UIImage(named: "checked") |
return iv |
}() |
|
let sepetLabel: UILabel = { |
let label = UILabel() |
label.text = "sepetteki ürün" |
label.textColor = .darkGray |
label.font = UIFont(name:"Comfortaa-Bold", size: 15) |
label.translatesAutoresizingMaskIntoConstraints = false |
return label |
}() |
|
let countBasketLabel: UILabel = { |
let countLabel = UILabel() |
countLabel.text = "x0" |
countLabel.textColor = .orange |
countLabel.font = UIFont(name:"Comfortaa-Bold", size: 15) |
countLabel.translatesAutoresizingMaskIntoConstraints = false |
return countLabel |
}() |
|
let priceBasketLabel: UILabel = { |
let pricelabel = UILabel() |
pricelabel.textColor = .black |
pricelabel.font = UIFont(name:"Comfortaa-Bold", size: 15) |
return pricelabel |
}() |
|
let deleteButton: UIButton = { |
let button = UIButton(type: .system) |
button.setImage(UIImage(named: "delete"), for: .normal) |
button.tintColor = .black |
button.layer.cornerRadius = 5 |
button.addTarget(self, action: #selector(testdetail.deleteAction(sender:)), for: .touchUpInside) |
return button |
}() |
lazy var addButton: UIButton = { |
let button = UIButton(type: .system) |
button.setImage(UIImage(named: "add"), for: .normal) |
button.tintColor = .black |
button.layer.cornerRadius = 5 |
return button |
}() |
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { |
super.init(style: style, reuseIdentifier: reuseIdentifier) |
setup() |
} |
|
required init?(coder aDecoder: NSCoder) { |
fatalError("init(coder:) has not been implemented") |
} |
|
|
func setup() { |
backgroundColor = .clear |
addSubview(cellView) |
cellView.addSubview(sepetLabel) |
cellView.addSubview(priceBasketLabel) |
cellView.addSubview(countBasketLabel) |
cellView.addSubview(addButton) |
cellView.addSubview(deleteButton) |
|
cellView.anchor(top: topAnchor, left: leftAnchor, bottom: bottomAnchor, right: rightAnchor, paddingTop: 4, paddingLeft: 8, paddingBottom: 4, paddingRight: 8, width: 40, height: 40) |
|
sepetLabel.anchor(top: nil, left: cellView.leftAnchor, bottom: nil, right: rightAnchor, paddingTop: 0, paddingLeft: 6, paddingBottom: 0, paddingRight: 0, width: 25, height: 25) |
sepetLabel.centerYAnchor.constraint(equalTo: cellView.centerYAnchor).isActive = true |
|
priceBasketLabel.anchor(top: nil, left: nil, bottom: nil, right: deleteButton.leftAnchor, paddingTop: 0, paddingLeft: 10, paddingBottom: 0, paddingRight: 20, width: 0, height: 35) |
priceBasketLabel.centerYAnchor.constraint(equalTo: sepetLabel.centerYAnchor).isActive = true |
|
countBasketLabel.anchor(top: nil, left: nil, bottom: nil, right: addButton.leftAnchor, paddingTop: 0, paddingLeft: 1, paddingBottom: 0, paddingRight: 1, width: 30, height: 25) |
countBasketLabel.centerYAnchor.constraint(equalTo: sepetLabel.centerYAnchor).isActive = true |
|
addButton.anchor(top: nil, left: nil, bottom: nil, right: rightAnchor, paddingTop: 0, paddingLeft: 2, paddingBottom: 0, paddingRight: 8, width: 30, height: 30) |
addButton.centerYAnchor.constraint(equalTo: sepetLabel.centerYAnchor).isActive = true |
|
deleteButton.anchor(top: nil, left: nil, bottom: nil, right: countBasketLabel.leftAnchor, paddingTop: 0, paddingLeft: 2, paddingBottom: 0, paddingRight: 8, width: 30, height: 30) |
deleteButton.centerYAnchor.constraint(equalTo: sepetLabel.centerYAnchor).isActive = true |
} |
} |