使用自动布局

时间:2016-02-24 12:03:04

标签: ios objective-c autolayout uilabel

现在我有2个UILabel,它们的总宽度是固定的,我想将它们并排放置,并使它们的文本右对齐。所以我写(使用砌体):

[self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make){
    make.top.equalTo(self.abstractLabel.mas_bottom).offset(verticalInnerSpacing);
    make.bottom.equalTo(self.contentView.mas_bottom).offset(-bottomOffset);
    make.left.equalTo(self.dateLabel.mas_right);
    make.right.equalTo(self.contentView.mas_right).offset(-rightOffset);
}];

[self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make){
    make.top.equalTo(self.authorLabel.mas_top);
    make.bottom.equalTo(self.authorLabel.mas_bottom);
    make.left.equalTo(self.thumbImage.mas_right).offset(horizontalInnerSpacing);
    make.right.equalTo(self.authorLabel.mas_left);
}];

但是,正确的标签的宽度始终大于文字大小。我想要实现的是左侧标签可能在其文本前面有一个空白区域,但右侧标签的宽度取决于其文本。那我该怎么办? 在这两个图像中,第一个是当前效果,第二个是我想要的效果。 Current effect My desired effect

0 个答案:

没有答案
相关问题