Posted at

Swiftで文字列の表示幅を取得する方法

More than 3 years have passed since last update.

let text = "表示幅を知りたい文字列"

let font = UIFont(name: "Hiragino Kaku Gothic ProN", size: 18)
let width = text.sizeWithAttributes([NSFontAttributeName : font])