我有一个UILabel
,可以根据其内容更改其高度。以图形方式,UILabel
可以做到这一点,但是当我在代码中打印UILabel
高度时,它总是返回0.0。有人可以解释吗?预先感谢。
代码:
private func loadDishDetails() -> () {
print(HttpRequestUrls.dishes + "/\(selectedDish.getIngredientId())")
Alamofire.request(HttpRequestUrls.dishes + "/\(selectedDish.getIngredientId())", method: .get, parameters: nil).validate(statusCode: 200..<300).responseString { response in
response.result.ifSuccess {
let jsonHttpResponse : JSON = JSON.init(parseJSON: response.value!)
self.descriptionLabel.text = jsonHttpResponse["description"].stringValue
for step in jsonHttpResponse["preparationSteps"].arrayValue {
self.preparationStepsLabel.text = self.preparationStepsLabel.text! + step.stringValue + "\n"
}
self.preparationStepsLabel.layoutIfNeeded()
self.descriptionLabel.layoutIfNeeded()
print(self.preparationStepsLabel.frame)
print(self.descriptionLabel.frame)
self.viewHeight.constant = self.viewHeight.constant + self.preparationStepsLabel.bounds.size.height
}
response.result.ifFailure {
self.descriptionLabel.text = "Nessuna descrizione"
self.preparationStepsLabel.text = "Nessuna preparazione"
}
}
}