I want to display an image next to a 'UILabel', however 'UILabel' has variable text length, so I don't know where to place the image.
Image should move according to the size of the label.
How can I accomplish this?
Although Keshav answer will work, it's deprecated
try:
NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:14]};
CGRect rect = [textToMeasure boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes
context:nil];
Then use the Size of rect to determine your positioning and label size.
CGRect currentLabelFrame = self.label.frame;
currentLabelFrame.size.width = rect.size.width;
self.label.frame = currentLabelFrame;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With