ios - oc 如何获得用 Masonry 约束好的宽度?
阿神
阿神 2017-04-18 09:43:42
0
4
865

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));
    }];
阿神
阿神

闭关修行中......

reply all(4)
小葫芦

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...

巴扎黑
  1. Extract 45 as a variable

  2. 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

迷茫

Get it from NSConstraint.

迷茫

After setting up, force refresh setNeedDisplay and then you can get the attributes after the forced refresh through the frame

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template