oc 如何获得用 Masonry 约束好的宽度?
例子:
/// 怎样获取里面约束好的 45 呢?请问!!
[self.choseCityBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@(12));
make.width.equalTo(@(45));
make.height.equalTo(@(24));
make.centerY.equalTo(@(navCenterY));
}];
高洛峰2017-04-18 09:45:42
In View
- (void)layoutSubviews {
[super layoutSubviews];
// 获取到约束后的控件frame
}
In controller
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// 获取到约束后的控件frame
}
Reference materials: https://github.com/SnapKit/Ma...
Other information: http://elijahdou.github.io/ui...
巴扎黑2017-04-18 09:45:42
Extract 45 as a variable
All constraints loaded through masonry can be passed
NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.choseCityBtn]
Get.
Then you loop through the array and find the constraint you want
迷茫2017-04-18 09:45:42
After setting up, force refresh setNeedDisplay and then you can get the attributes after the forced refresh through the frame