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