Thursday, November 11, 2010

iPhone: Attach an image with one line of code


iPhone: Attach an image with one line of code

I got sick of the 4 lines of code it takes to attach and garbage collect a UIImageView to your UIView, so I wrote a static function for our DisplayUtil class to clean up this process. Check it out below and feel free to use:
+ (UIImageView*)attachImageToView:(UIView*)viewObject withId:(NSString*)imgId andRect:(CGRect)rect {
 UIImageView *img = [[UIImageView alloc] initWithFrame:rect];
 img.image = [UIImage imageNamed:imgId];
 [viewObject addSubview:img];
 [img release];
 return img;
}

No comments:

Post a Comment

There was an error in this gadget
There was an error in this gadget

Followers