imageView中的图像对齐问题 - 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 加载的图像的大小?
I have following code in my application:
// 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];
I want the following:
- Suppose an image ( which is loaded through nsdata ) is having size of 60 x 60 then content mode should be UIVIewContentModeCenter
- Suppose an image ( which is loaded through nsdata ) is having more size then 60 x 60 then content mode should be UIViewContentModeScaleToFill.
But my question is how can I determine the size of the image loaded through NSData
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以删除以下行,因为
UIImageView
将根据用于初始化它的图像调整自身大小:从那里您可以通过获取
UIImageView
的大小来获取图像的大小代码>:You can remove the following line because the
UIImageView
will size itself according to the image used to initialize it:From there you can get the size of the image by taking the size of the
UIImageView
:我尝试了以下代码&它起作用了。
I tried following code & it worked.