Skip to content

Instantly share code, notes, and snippets.

@hpp-hash
Created September 4, 2019 21:49
Show Gist options
  • Save hpp-hash/f16fb09c73ae247f7e481d62a062414e to your computer and use it in GitHub Desktop.
Save hpp-hash/f16fb09c73ae247f7e481d62a062414e to your computer and use it in GitHub Desktop.
Adjust UI View's height constraint based on the iPhone's height
// iPhone 8 - each view is 220
if (UIScreen.main.bounds.height == 667.0) {
for constraint in self.backgroundChartView.constraints {
if constraint.identifier == "chartHeightConstraint" {
constraint.constant = 220
}
}
for constraint in self.tableViewBackground.constraints {
if constraint.identifier == "tableHeightConstraint" {
constraint.constant = 220
}
}
}
// iPhone 8 Plus/ iPhone XS - each view is 260
if (UIScreen.main.bounds.height == 736.0 || UIScreen.main.bounds.height == 812.0) {
for constraint in self.backgroundChartView.constraints {
if constraint.identifier == "chartHeightConstraint" {
constraint.constant = 260
}
}
for constraint in self.tableViewBackground.constraints {
if constraint.identifier == "tableHeightConstraint" {
constraint.constant = 260
}
}
}
// update sublayouts
self.backgroundChartView.layoutIfNeeded()
self.tableViewBackground.layoutIfNeeded()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment