开发者

setting size of UIImageView in a UITableView cell programmatically - what is the origin?

开发者 https://www.devze.com 2023-01-15 14:00 出处:网络
I\'m trying to set the size of a UIImageView programmatically using: [thisImageView setFrame:CGRec开发者_JAVA技巧tMake(x, y, image.size.width, image.size.height)];

I'm trying to set the size of a UIImageView programmatically using:

[thisImageView setFrame:CGRec开发者_JAVA技巧tMake(x, y, image.size.width, image.size.height)];

I tried using x = 0, y = 0, but the UIImageView disappears.

More info on why I'm trying to do this. I'm trying to display a high-res image on an iPhone 4 without using the iOS 4 SDK (only using 3.2 SDK API calls). I have calls to see if I'm on an iPhone 4, so I'm trying to double the size of my UIImageView so that when I put the high-res UIImage in, it won't be grainy.


Not sure what there is so special about iOS. Just use the same method you use with 3.2: imageNamed: ... it will take care of everything as long as your images are named properly (yourimagename.png and yourimagename@2x.png). Nothing fancy in the iOS 4 SDK here, just give the size you use in points as before.

If this is not suitable in your case, can you explain why?


I'm trying to display a high-res image on an iPhone 4 without using the iOS 4 SDK (only using 3.2 SDK API calls)

Ouch. Don't do that.

Compile against 4.0, set the deployment target to 3.whatever.

When creating the image, check [UIImage respondsToSelector:@selector(imageWithCGImage:scale:orientation:)]. If it does, then you can use +[UIImage imageWithCGImage:scale:orientation:] to create a "scale 2" image, which will display correctly in a UIImageView on iPhone 4 (which has a "scale 2" screen).

If you really can't use the OS 4 SDK (you don't seem to state a reason why), then make the UIImageView smaller using the appropriate content mode (AspectFit/AspectFill/ScaleToFill), and set its frame to half the size in pixels (e.g. if the image is 100x100 px, set it to (CGSize){50,50}). This shrinks the image to half-size, but the double-res screen means you see it pixel-for-pixel.


I think your approach is wrong. iPhone 4 works with points instead of pixels, which makes doubling the size troublesome. 1 point on old devices equals 4 pixels on iPhone 4, but is still used as 1 point.

When you create the frame you're not actually giving the API the pixel dimensions, but the point dimensions.

0

精彩评论

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