Created
September 4, 2019 21:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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