2016-12-12 1 views
0
contentLabel.preferredMaxLayoutWidth = kScreenWidth - 20 
contentLabel.numberOfLines = 0 

저는 SnapKit을 사용하여 위쪽과 왼쪽을 설정합니다.왜 라벨의 높이가 0입니까?

contentLabel.snp.makeConstraints { (make) in 
    make.top.equalTo(topView.snp.bottom) 
    make.left.equalTo(topView.iconView) 
} 
print(contentLabel.frame.size.height) 

0을 출력합니다. 괜찮습니까?

답변

1

당신은 스위프트 3이 기능에 의해 라벨 높이를 얻을 수 있습니다 :

func GetheightOfLable(strLable:String , widthlable:CGFloat) -> CGFloat{ 

    let rectDetail:CGRect = strLable.boundingRect(with: CGSize(width: widthlable, height: CGFloat(MAXFLOAT)), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: [NSFontAttributeName:UIFont.systemFontSize], context: nil) 
    print(rectDetail.height) 
    return rectDetail.height 
} 
당신이 시도 할 수
0

, 난 그것이 당신에게

도움이 될 것입니다 희망 당신에게
let sizeToFit = CGSize(width: contentLabel.frame.size.width, 
         height: CGFloat.greatestFiniteMagnitude) 
let textSize = contentLabel.sizeThatFits(sizeToFit) 

도움이 될 것입니다 생각