ios - NSString boundingRect with image glyphs included within UILabel -



ios - NSString boundingRect with image glyphs included within UILabel -

i'm attempting determine appropriate height uilabel need when constrained max width nsattributedstring label.

the problem i'm running height calculation off when include little image @ end of uilabel.

here i'm doing.

@property (nonatomic, weak) iboutlet uilabel *fullname; // append first , lastly name nsmutableattributedstring *fullname = [[nsmutableattributedstring alloc] initwithstring:[nsstring stringwithformat:@"%@ %@", firstname, lastname] attributes:@{ nsfontattributename : [uifont systemfontofsize:16], nsforegroundcolorattributename : fontcolor }]; // append image nstextattachment *textattachment = [[nstextattachment alloc] init]; textattachment.image = [uiimage imagenamed:@"starimage"]; nsattributedstring *attrstringwithimage = [nsattributedstring attributedstringwithattachment:textattachment]; [fullname appendattributedstring:attrstringwithimage]; // set label attributedtext self.fullname.attributedtext = fullname;

later phone call helper method determine height fullname label need.

- (cgfloat)heightoflabel:(uilabel *)label withmaxwidth:(cgfloat)width { cgsize boundingsize = cgsizemake(width, flt_max); homecoming [label.text boundingrectwithsize:boundingsize options:nsstringdrawinguseslinefragmentorigin attributes:@{nsfontattributename:label.font} context:nil].size.height; }

this problem little image append isn't taken account. i've tried label.attributedtext instead of label.text no result.

any thoughts or suggestions? thanks.

i don't know why boundingrectwithsize:options:attributes:context: doesn't work, much simpler size method does. take business relationship size of image.

cgsize *stringsize = fullname.size;

ios objective-c uilabel nsattributedstring

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -