我把这个方法用在控件上
for (int i = 0; i < self.subviews.count; ++i) {
UIView *subView = self.subviews[i];
for (int j = 0; j < subView.constraints.count; ++j) {
NSLayoutConstraint *layoutConstraint = subView.constraints[j];
layoutConstraint.constant = kAdaWidth(layoutConstraint.constant);
NSLog(@"%f",layoutConstraint.constant);
}
}
#define kWidthRatio (kScreenWidth / 375.0)
#define kHeightRatio (kScreenHeight / 667.0)
#define kAdaWidth(x) ceilf((x) * kWidthRatio)
#define kAdaHeight(x) ceilf((x) * kHeightRatio)