剛接觸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
經(jīng)過搜索才發(fā)現(xiàn),swift 中option類型變?yōu)榱薕ptionSet類型,查看鏈接
所以要把上面組合方法改為下面就好了
let option: NSStringDrawingOptions = [.usesLineFragmentOrigin,.truncatesLastVisibleLine]
參考文章:
https://www.iteye.com/news/30052