wouter
(wouter)
1
Hey All,
I got a dynamic table which i fill using a an array. The problem is i have some issues setting the constraints.
This is the result i get.

The second part (second orange block) is barely visible. I would like to make the gray area bigger and add some padding inside the gray cell. Also i would like to add some space between the 2nd cell and the 3rd cell (and between the 4th and 5th cell and so on)
class CustomCell: UITableViewCell {
var parent: String?
var maintit: String?
var comments: String?
var parentView : UITextView = {
var textView = UITextView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.backgroundColor = orangeBanner
return textView
}()
var mainView : UITextView = {
var textView = UITextView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.backgroundColor = grayBanner
return textView
}()
var commentView : UITextView = {
var textView = UITextView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.backgroundColor = grayBanner
return textView
}()
var intTitleTable: UITableView = {
var m = UITableView()
m.backgroundColor = grayBanner
m.separatorStyle = .none
return m
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?){
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.addSubview(intTitleTable)
self.addSubview(parentView)
self.addSubview(mainView)
self.addSubview(commentView)
intTitleTable.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
intTitleTable.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
intTitleTable.widthAnchor.constraint(equalToConstant: 400).isActive = true
intTitleTable.heightAnchor.constraint(equalToConstant: 400).isActive = true
parentView.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
parentView.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
parentView.topAnchor.constraint(equalTo: self.intTitleTable.topAnchor).isActive = true
parentView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
mainView.topAnchor.constraint(equalTo: parentView.bottomAnchor).isActive = true
mainView.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
mainView.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
mainView.heightAnchor.constraint(equalToConstant: 30).isActive = true
}
override func layoutSubviews() {
super.layoutSubviews()
if let parent = parent {
parentView.text = parent
}
if let maintit = maintit {
mainView.text = maintit
}
}
required init?(coder aDecoder: NSCoder){
fatalError("init(coder:) has not been implemented")
}
}
eskimo
(Quinn “The Eskimo!”)
2
As this is more about table view cells than it is about Swift, you might have more luck asking it somewhere dedicated to UIKit questions, like the App Frameworks > Cocoa Touch topic area on DevForums.
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple
wouter
(wouter)
3
For any1 whos wondering, or having the same problem. Solved it by using UIStackview. Thsi gives you the freedom to set the desired width and height.