iOS开发 自动布局

2020-04-20  本文已影响0人  Leoeoo

一:NSLayoutConstraint

_showFileWebView 添加到 _webViewSuperView上,且上下左右与父视图对齐。

_showFileWebView = [[WKWebView alloc] init];
[_webViewSuperView addSubview:_showFileWebView];

_showFileWebView.translatesAutoresizingMaskIntoConstraints = NO;
NSLayoutConstraint *topC = [NSLayoutConstraint constraintWithItem:_showFileWebView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_webViewSuperView attribute:NSLayoutAttributeTop multiplier:1 constant:0];
[_webViewSuperView addConstraint:topC];

NSLayoutConstraint *leftC = [NSLayoutConstraint constraintWithItem:_showFileWebView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_webViewSuperView attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
[_webViewSuperView addConstraint:leftC];

NSLayoutConstraint *rightC = [NSLayoutConstraint constraintWithItem:_showFileWebView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_webViewSuperView attribute:NSLayoutAttributeRight multiplier:1 constant:0];
[_webViewSuperView addConstraint:rightC];

NSLayoutConstraint *bottomC = [NSLayoutConstraint constraintWithItem:_showFileWebView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:_webViewSuperView attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
[_webViewSuperView addConstraint:bottomC];
[_webViewSuperView layoutIfNeeded];
上一篇 下一篇

猜你喜欢

热点阅读