Senthil Senthil - 1 year ago 89
iOS Question

Prevent Stretching image from uiimage in iphone sdk

enter image description here

Code snippet

self.newsImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,300,130)];
//set placeholder image or cell won't update when image is loaded
self.newsImage.image = [UIImage imageNamed:@"newsDetail.png"];
//load the image
self.newsImage.imageURL = [NSURL URLWithString:imageBig];
[imageBack addSubview:self.newsImage];

I have one image on 40*40 size but image view size 300*130. How to avoid stretching image.

I want center of the UIImageview.

Thanks in Advance !!!!

Answer Source

Just center the content:

self.newsImage.contentMode = UIViewContentModeCenter;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download