美文网首页
2024-07-17

2024-07-17

作者: 时光流逝_6602 | 来源:发表于2024-07-16 09:57 被阅读0次

    此代码通过设置自动布局约束条件来确保 timeLabel 始终完全显示,并且与 titleLabel 保持 12 点的间距。通过调整内容抗拉伸优先级和内容压缩抗拉伸优先级,确保 timeLabel 优先显示, titleLabel 根据剩余空间调整其宽度。

        //标题

        [self.contentView addSubview:self.titleLabel];

        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.mas_equalTo(self.iconImageView.mas_right).mas_offset(SLMargin);

            make.top.mas_equalTo(SLMargin);

            make.right.mas_equalTo(self.timeLabel.mas_left).mas_offset(-12);

        }];

        //时间

        [self.contentView addSubview:self.timeLabel];

        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {

            make.right.mas_equalTo(-SLMargin);

            make.centerY.mas_equalTo(self.titleLabel);

            make.left.mas_greaterThanOrEqualTo(self.titleLabel.mas_right).mas_offset(12);

        }];

        [self.titleLabel setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];

        [self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];

        [self.timeLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

        [self.timeLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

    相关文章

      网友评论

          本文标题:2024-07-17

          本文链接:https://www.haomeiwen.com/subject/tslkhjtx.html