Last active
January 27, 2017 08:45
-
-
Save tid-kijyun/4c1b786061c1e8e8676078b44b2de98f to your computer and use it in GitHub Desktop.
byWordWrappingな文字列に必要な高さを求めてみる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func heightForStringDrawing2(myString: String, myFont: NSFont, myWidth: CGFloat) -> CGFloat { | |
let paragraphStyle = NSMutableParagraphStyle() | |
paragraphStyle.lineBreakMode = .byWordWrapping | |
let attribute: [String : Any] = [ | |
NSFontAttributeName: myFont, | |
NSParagraphStyleAttributeName: paragraphStyle | |
] | |
let constraintsSize = CGSize(width: myWidth, height: CGFloat(FLT_MAX)) | |
let textSize = NSString(string: myString).boundingRect(with: constraintsSize, options: .usesLineFragmentOrigin, attributes: attribute, context: nil) | |
return textSize.height | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment