0
我已经在我的应用程序下面的代码:图像对齐问题 - iPhone
// to set tip - photo in photo frame
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:pathOfThumbNail]];
UIImage *cellThumbImg;
if([data length]>0){
cellThumbImg = [UIImage imageWithData:data];
} else {
cellThumbImg = [UIImage imageNamed:@"130X90.gif"];
}
UIImageView *imgView = [[UIImageView alloc]initWithImage:cellThumbImg];
imgView.frame = photoFrame;
[imgBg setContentMode:UIViewContentModeScaleToFill];
[cell.contentView addSubview:imgView];
//[cell.contentView sendSubviewToBack:imgView];
[imgView release];
[data release];
我想以下几点:
- 假设一个图像(这是通过NSData的加载)由具有大小60 x 60,那么内容模式应该是UIVIewContentModeCenter
- 假设图像(通过nsdata加载)具有更多大小,然后60 x 60,那么内容模式应该是UIViewContentModeScaleToFill。
但我的问题是如何确定通过NSData
加载的图像的大小?
imgView.frame=photoFrame;
从那里,你可以通过采取UIImageView
的尺寸得到了图像的大小:
@fbrereton - 先生,您说得对。然而,我尝试了一些不同的东西,并在下面的答案中加入。 – 2009-09-02 17:17:30