刚接触Swift,我们都知道,在oc中使用option类型只要|就好了,
在swift中,我尝试下面这样会报错
let paragraph = NSMutableParagraphStyle.init()
paragraph.lineBreakMode = .byWordWrapping
letattribute = [NSAttributedString.Key.font: font,NSAttributedString.Key.paragraphStyle: paragraph]
letoption:NSStringDrawingOptions= .usesLineFragmentOrigin | .truncatesLastVisibleLine
letsize =self.boundingRect(with:CGSize(width:100.202, height: height), options: option, attributes: attribute, context:nil).size
经过搜索才发现,swift 中option类型变为了OptionSet类型,查看链接
所以要把上面组合方法改为下面就好了
let option: NSStringDrawingOptions = [.usesLineFragmentOrigin,.truncatesLastVisibleLine]
参考文章:
https://www.iteye.com/news/30052