user2636197
user2636197

Reputation: 4122

Swift change constraint values in viewdidload

I have a tableView that containts a image in each cell. When the app starts I check if the user is using a iphone 5 or iphone 6 plus then I change the cell height and image height constraint to fit the device.

Right now I change the height constraint inside viewDidLoad but is this the right place?

Upvotes: 0

Views: 189

Answers (1)

CFlux
CFlux

Reputation: 345

I prefer to use a tableView function:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

    return [DESIRED HEIGHT]
}

This way you can create conditions for each type of cell and set their height here.

The image constraints should be related to the cell's bounds.

Upvotes: 1

Related Questions