How to stretch the image size in iphone UIImage or UIImageView

ぃ、小莉子 提交于 2019-12-30 02:16:29

问题


I'd like to show an image in an iPhone app, but the image I'm using is too big. I'd like to scale it to fit the iPhone screen, I can't find any class to handle it.


回答1:


UIImageView* view = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"your_image.png"]];
view.frame = CGRectMake(0, 0, width, height);

To get the frame of the iPhone screen you can use

CGRect frame = [[UIScreen mainScreen] bounds];



回答2:


In Interface Builder, select your UIImageView. From the Tools menu, select "Attribute Inspector". In the Image View Attributes palette, select "Scale to Fill" from the Mode popup. That should scale your image to fit.




回答3:


My ImageView was set in IB, and I would need to show multiple images, so set the image of imageView, instead of creating ImageView for individual image.

After I set the image view frame size, I am still see the same result, the image was too big, so that only part of the image was displayed on the screen.



来源:https://stackoverflow.com/questions/245349/how-to-stretch-the-image-size-in-iphone-uiimage-or-uiimageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!