IOS Compute Text Height

Source: Internet
Author: User

#pragma mark-once Get text height

-(Cgsize) Sizewithmaxsize: (cgsize) size antext: (NSString *) anstring

{

nsmutableattributedstring *attributedstring = [[Nsmutableattributedstring alloc] initwithstring:anstring];

Nsmutableparagraphstyle *style = [[Nsmutableparagraphstyle alloc]init];

[Style setlinespacing:6.0f];

[Attributedstring addattribute:nsparagraphstyleattributename Value:style range:nsmakerange (0, [anString length])];

Cgsize realsize = Cgsizezero;

if (System_version_greater_than_or_equal_to (@ "7.0")) {

CGRect textrect = [anstring boundingrectwithsize:size options:nsstringdrawinguseslinefragmentorigin attributes:@{ Nsfontattributename:[uifont Systemfontofsize:myconsuldetailframefontsize],nsparagraphstyleattributename:style} Context:nil];

Realsize = textrect.size;

} else {

Realsize = [anstring sizewithfont:[uifont systemfontofsize:myconsuldetailframefontsize] maxSize:size lineBreakMode: Nslinebreakbycharwrapping];

}

Realsize.width = Ceilf (realsize.width);

Realsize.height = Ceilf (realsize.height);

return realsize;

}


This article is from the "11204872" blog, please be sure to keep this source http://11214872.blog.51cto.com/11204872/1770197

IOS Compute Text Height

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.