美文网首页
iOS bug----label自适应宽度

iOS bug----label自适应宽度

作者: 橘子味草莓 | 来源:发表于2017-06-06 16:57 被阅读82次

    self.commentNumber=[[UILabel alloc]init];

    self.commentNumber.numberOfLines=0;

    self.commentNumber.text=[NSString stringWithFormat:@"%@",self.model.comment_num];

    CGRect rectcomment = [self.commentNumber.text boundingRectWithSize:size options:NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : Font11} context:nil];

    [self.commentNumber setFont:[UIFont systemFontOfSize:11]];

    [self.commentNumber setTextColor:[UIColor grayColor]];

    [self.commentNumber sizeToFit];

    self.commentNumber.textAlignment=NSTextAlignmentCenter;

    [self.contentView addSubview:self.commentNumber];

    self.commentNumber.sd_layout

    .rightSpaceToView(self.likeBtn,15)

    .topSpaceToView(self.contentLa,11)

    .widthIs(rectcomment.size.width)

    .heightIs(rectcomment.size.height);

    把赋值放在自适应的前面就可以了

    相关文章

      网友评论

          本文标题:iOS bug----label自适应宽度

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