// 得到字符串的高度
func getTextHeight(text :String,width: CGFloat,fontSize :CGFloat = 14) -> CGFloat {
let textNormal = text as NSString
let size = CGSizeMake(width, 1000)
let font = UIFont.systemFontOfSize(fontSize)
let dic = NSDictionary(object: font , forKey: NSFontAttributeName)
let strSize = textNormal.boundingRectWithSize(size, options: .UsesLineFragmentOrigin , attributes: dic as? [String : AnyObject], context: nil).size
return strSize.height
}
这样就可以根据后台返回的数据进行不同高度的设置了