使用这个函数
主要
固定宽度
var font = UIFont.systemFontOfSize(14);
var attribute = NSMutableDictionary()
attribute.setObject(font,forKey: NSFontAttributeName)
var rect = yourString.boundingRectWithSize(CGSizeMake(yourWidth,CGFloat.max),options: NSStringDrawingOptions.UsesLineFragmentOrigin,attributes: attribute as [NSObject : AnyObject],context:nil)