mardi 23 juin 2015

UITableViewCell Percentage Based Height with Minimum Height

I have a custom tableview cell where I'm letting auto layout manage the height for it.

tableView.estimatedRowHeight = 44 
tableView.rowHeight = UITableViewAutomaticDimension

Inside the TableViewCell I have a subview:

contentView.addSubview(subView)

I'd like the TableViewCell to be either 40% of the screen's height or 250pts.

I've gotten it to work by doing this:

self.contentView.autoSetDimension(.Height, toSize: round(UIScreen.mainScreen().bounds.height * 0.40), relation: .GreaterThanOrEqual)
self.contentView.autoPinEdgeToSuperviewEdge(.Leading)
self.contentView.autoPinEdgeToSuperviewEdge(.Trailing)
self.subView.autoSetDimension(.Height, toSize: 250, relation: .GreaterThanOrEqual)

subView.autoPinEdgeToSuperviewEdge(.Top)
subView.autoPinEdgeToSuperviewEdge(.Leading)
subView.autoPinEdgeToSuperviewEdge(.Trailing)
subView.autoPinEdgeToSuperviewEdge(.Bottom)

This looks kind of sloppy to me. Is this the best way to do this?

See more ..

Aucun commentaire:

Enregistrer un commentaire