IOS Compute uilable String height

Source: Internet
Author: User

Before IOS7

Intercepted part of

@interface Zgviewcell ()

@property (nonatomic, strong) UILabel *namelable;

@end

-(UILabel *) namelable{

if (_namelable = = nil) {

_namelable = [[UILabel alloc] init];

[Self. contentview addsubview:_namelable];

_namelable.backgroundcolor = [Uicolor Redcolor];

The default font is, "..." will appear

_namelable. font = [uifont fontwithname:@ "Arial" size: +];

}

return _namelable;

}

location

-(void) settingframe{

cgfloat padding = ten;

icons

cgfloat IconX = padding;

cgfloat icony = padding;

cgfloat iconw = ;

cgfloat iconh = ;

Self . Iconimage. frame = CGRectMake (IconX, Icony, Iconw, Iconh);

// name

Uifont *namefont = [uifont fontwithname:@ "Arial" size:14.0f];

cgsize nameframe = [self. Statuses. Name sizewithfont: Namefont constrainedtosize: Cgsizemake(maxfloat, maxfloat) Linebreakmode: nslinebreakbywordwrapping];

cgfloat NameX = Cgrectgetmaxx (self. Iconimage. frame) + padding;

cgfloat Namey = (self. Iconimage. frame. size. Height-nameframe. height) * 0.5 + padding;

Self . namelable. frame = CGRectMake (NameX, Namey, Nameframe. width, nameframe. height);

}

IOS 7 Apple adds a lot of ways to UIStringDrawing.h

corresponding to the above

/** Boundingrectwithsize calculates the area occupied by a given text string

The return value is an x, y = 0 cgrect

If you want to calculate the exact height of multiple rows, you need to pass in the Nsstringdrawinguseslinefragmentorigin option

Dict dictionary that specifies the related properties of the font, the first header file in the Uikit frame

*/

location

-(void) settingframe{

Nsdictionary *namedict = @{nsfontattributename: [Uifont systemfontofsize:+]} ;

CGRect nameframe= [str boundingrectwithsize:cgsizemake (maxfloat, maxfloat) options: Nsstringdrawinguseslinefragmentorigin attributes:namedict context: nil];

nameframe.origin.x = Cgrectgetmaxx (self.iconImage.frame) + padding;

NAMEFRAME.ORIGIN.Y = (self. Iconimage. frame. size. Height-nameframe. height) * 0.5 + padding;

Self. namelable. frame = nameframe;

}

IOS Compute uilable String 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.