Senthil Senthil - 3 months ago 17
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

Just center the content:

self.newsImage.contentMode = UIViewContentModeCenter;
Comments