search

Home  >  Q&A  >  body text

ios - oc 如何获得用 Masonry 约束好的宽度?

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

reply all(4)I'll reply

  • 高洛峰

    高洛峰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...

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:45:42

    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

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:45:42

    Get it from NSConstraint.

    reply
    0
  • 迷茫

    迷茫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

    reply
    0
  • Cancelreply