Masonry适配控件被拉伸问题

2017-07-12  本文已影响63人  咋了爸爸

布局如下:

屏幕快照 2017-07-12 下午2.55.57.png

采用masonry适配, 只给了图片的left 以及 centerY坐标,

 self.titleImageV = [[UIImageView alloc] init];
    
    [self.backImageV addSubview:self.titleImageV];
    
    [self.titleImageV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(10);
        
        make.centerY.mas_equalTo(self.backImageV.mas_centerY);

    }];

然后运行程序,发现图片没问题,还原原有的尺寸,之后后面的label给left、right、以及centerY,

 
    self.titleL = [[UILabel alloc] init];
    
    self.titleL.textColor = [UIColor whiteColor];
    
    self.titleL.font = [UIFont systemFontOfSize:13 * sHeight];
    self.titleL.numberOfLines = 0;
    [self.backImageV addSubview:self.titleL];
    
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleImageV.mas_right).offset(6 * sWidth);
        
        make.right.mas_equalTo(-6 * sWidth);
        
        make.centerY.mas_equalTo(self.backImageV.mas_centerY);
    }];

结果发现图片被拉伸了 ,

解决办法 : 被拉伸的控件水平抗压缩 如下代码

[self.titleImageV setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
上一篇下一篇

猜你喜欢

热点阅读