rightBarButtonItem 不能用Masonry来约束

  UIView *rightBarContentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 87, 32)];
                rightBarContentView.layer.cornerRadius = 16;
                rightBarContentView.layer.borderWidth = 0.5;
                rightBarContentView.layer.borderColor = HexRGB(0xEAEAEA).CGColor;
                rightBarContentView.layer.masksToBounds = YES;
                UIButton *aboutBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 86/2.0, 32)];
                [aboutBtn setImage:[UIImage imageNamed:@"mini_about"] forState:UIControlStateNormal];
                [aboutBtn addTarget:self action:@selector(aboutBntAction:) forControlEvents:UIControlEventTouchUpInside];
                [rightBarContentView addSubview:aboutBtn];
                
                UIButton *closeBtn = [[UIButton alloc]initWithFrame:CGRectMake(86/2.0+1, 0, 86/2.0, 32)];
                [closeBtn setImage:[UIImage imageNamed:@"mini_close"] forState:UIControlStateNormal];
                [closeBtn addTarget:self action:@selector(closeBntAction:) forControlEvents:UIControlEventTouchUpInside];
                [rightBarContentView addSubview:closeBtn];
                
                UIView *line = [[UIView alloc]initWithFrame:CGRectMake(86/2.0, (32-18.5)/2.0, 0.5, 18.5)];
                [rightBarContentView addSubview:line];
                line.backgroundColor = HexRGB(0xCCCCCC);
//                [line mas_makeConstraints:^(MASConstraintMaker *make) {
//                    make.width.equalTo(@0.5);
//                    make.height.equalTo(@18.5);
//                    make.center.equalTo(rightBarContentView);
//                }];
//                rightBarContentView.backgroundColor = [UIColor randomColor];
                 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBarContentView];

异常的情况,上面的masonry代码打开的时候.png
正常的情况,去掉masonry后.png

这是告诉我们,在新系统下,masonry不能用于uitexfield 和BarButtonItem上。

你可能感兴趣的:(rightBarButtonItem 不能用Masonry来约束)