开发者

iOS 3.1.2: UIImageViews not respecting frame size

I have a universal iOS application, and all of my images are sized for the iPad. To size them correctly on the iPhone, I use the UIImageView Frame property. However, I just tested out my app on an iPhone 1 running iOS 3.1.2, and all of the images are showing up full size! They show up correctly on every device running iOS 4 that I have tested on. Does anyone know why this is or how to fix it? I don't want to just make iPhone-sized versions of all my images, because I zoom in开发者_Python百科 and out of images in my app by changing their frame size.

Thanks! Anita


You can scale the image with half of the image size and scale to fill, will work which i do follow.

UIImage* originalImage = [UIImage imageNamed:@"demo.jpg"];
originalImage = [UIImage imageWithCGImage:[originalImage CGImage] scale:2.0 orientation:UIImageOrientationUp];

and wherever you are setting this image to any control lets say UIView

UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, originalImage.size.width, originalImage.size.height)];


If you are using a xib with interface builder, make sure you have set the autosizing for the UIImageView.

If you create the UIImageViews in code, you will want something like:

        myImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;


try remove

sizeToFit

property. I've the same issue and removing sizeToFit was solved.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜