How to calculate the height of an NSAttributedString with given width in iOS 6 [duplicate]

Option 2 does work in iOS with the proper parameters.

NSAttributedString *attrStr = ... // your attributed string
CGFloat width = 300; // whatever your desired width is
CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];

Without the proper values for the options parameter you will get the wrong height.

It is also required that attrStr contains a font attribute. Without a font, there is no way to properly calculate the size.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)