Can somebody help me here?. New as iPhone Developer. I am trying to display a .png picture in a circle instead of a rectangle which is the standard for iPhone
Well, all png files are 'rectangles' but if you want to have the apperence of a circle or other non rectangle object on the screen you can do so by using transparacy. To make sure the transparent pixels in the image are also transparent on the iPhone, you can set the background color of the UIImageView to clear. This can be done in Interface Builder by dragging the opacity slider in the background color picker all the way down, or in code as follows:
UIImage *image = [UIImage imageNamed:@"yourRoundImage.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.backgroundColor = [UIColor clearColor]; [self.view addSubview: imageView];
If you simply want to add rounder corners, to make a circle, you can also use the cornerRadius Property like this if you have added the QuartzCore framework to your project:
#import <QuartzCore/QuartzCore.h> UIImage *image = [UIImage imageNamed:@"yourRoundImage.png"]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.layer.cornerRadius = image.size.width / 2; imageView.layer.masksToBounds = YES; [self.view addSubview: imageView];
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