Yang's approach seems fine, but if you don't want to resize the label for some reason (text is centered, text will change, etc.), you might use the UIKit additions in NSString. Of course, this will only work properly for one-line labels.
CGSize textSize = [label.text sizeWithFont:label.font];
CGFloat imgX;
CGFloat imgY = label.frame.origin.y - imageView.frame.size.height;
if(label.textAlignment == UITextAlignmentLeft) {
imgX = label.frame.origin.x + textSize.width;
} else if(label.textAlignment == UITextAlignmentCenter) {
imgX = label.frame.origin.x + textSize.width / 2.0;
} else if(label.textAlignment == UITextAlignmentRight) {
// This part really depends on what you want to do in this case
imgX = label.frame.origin.x
+ label.frame.size.width
- textSize.width
- imageView.frame.size.width;
}
imageView.frame = CGRectMake(imgX,
imgY,
imageView.frame.size.width,
imageView.frame.size.height);