UITableViewCell的imageView适合40x40 [英] UITableViewCell's imageView fit to 40x40
问题描述
我在tableView和detailView中使用相同的大图像. 当imags在tableView中显示时,需要将imageView填充为40x40,但要在屏幕的一半上拉伸.我玩过一些游戏,但没有任何积极的结果:
I use the same big images in a tableView and detailView. Need to make imageView filled in 40x40 when an imags is showed in tableView, but stretched on a half of a screen. I played with several properties but have no positive result:
[cell.imageView setBounds:CGRectMake(0, 0, 50, 50)];
[cell.imageView setClipsToBounds:NO];
[cell.imageView setFrame:CGRectMake(0, 0, 50, 50)];
[cell.imageView setContentMode:UIViewContentModeScaleAspectFill];
我将SDK 3.0与预定义样式的单元格对象"一起使用.
I am using SDK 3.0 with build in "Cell Objects in Predefined Styles".
推荐答案
我将Ben的代码作为扩展名放在我的NS-Extensions文件中,这样我就可以告诉任何图像对其自身进行缩略图显示,例如:
I put Ben's code as an extension in my NS-Extensions file so that I can tell any image to make a thumbnail of itself, as in:
UIImage *bigImage = [UIImage imageNamed:@"yourImage.png"];
UIImage *thumb = [bigImage makeThumbnailOfSize:CGSizeMake(50,50)];
这是.h文件:
@interface UIImage (PhoenixMaster)
- (UIImage *) makeThumbnailOfSize:(CGSize)size;
@end
,然后在NS-Extensions.m文件中:
and then in the NS-Extensions.m file:
@implementation UIImage (PhoenixMaster)
- (UIImage *) makeThumbnailOfSize:(CGSize)size
{
UIGraphicsBeginImageContextWithOptions(size, NO, UIScreen.mainScreen.scale);
// draw scaled image into thumbnail context
[self drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newThumbnail = UIGraphicsGetImageFromCurrentImageContext();
// pop the context
UIGraphicsEndImageContext();
if(newThumbnail == nil)
NSLog(@"could not scale image");
return newThumbnail;
}
@end
这篇关于UITableViewCell的imageView适合40x40的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!