我的应用程序中有以下代码:
// 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
加载的图片的大小?
答案 0 :(得分:1)
您可以移除以下行,因为UIImageView
会根据用于初始化它的图像自行调整大小:
imgView.frame=photoFrame;
从那里你可以通过取UIImageView
:
CGRect image_bounds = imgView.frame;
答案 1 :(得分:0)
我尝试过以下代码&它奏效了。
// 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;
(cellThumbImg.size.height>60 || cellThumbImg.size.width>60 ) ?
[imgView setContentMode:UIViewContentModeScaleToFill] :
[imgView setContentMode:UIViewContentModeCenter] ;
[cell.contentView addSubview:imgView];
[imgView release]; [data release];