iOS masonry設置控件的優先級


1.效果  標題標題標題  時間;優先保證時間的完整顯示,標題過長就顯示...

//時間
        _timeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_timeLabel];
        _timeLabel.font = [UIFont systemFontOfSize:12];
        _timeLabel.textAlignment = NSTextAlignmentRight;
        _timeLabel.textColor = UIColorFromRGB(0x999999);
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.contentView.mas_right).offset(-11);
            make.top.equalTo(weakSelf.topClearView.mas_top).offset(16);
        }];
        
        //標題
        _titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        _titleLabel.numberOfLines = 1;
        _titleLabel.font = [UIFont systemFontOfSize:16];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.textColor = UIColorFromRGB(0x111111);
        _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.manyChooseButton.mas_right).offset(26);
            make.top.equalTo(weakSelf.topClearView.mas_top).offset(16);
            make.right.mas_lessThanOrEqualTo(self.timeLabel.mas_left).with.offset(-5);
        }];
        [self.titleLabel setContentCompressionResistancePriority:(UILayoutPriorityDefaultLow) forAxis:(UILayoutConstraintAxisHorizontal)];
        [self.timeLabel setContentCompressionResistancePriority:(UILayoutPriorityDefaultHigh) forAxis:(UILayoutConstraintAxisHorizontal)];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM