UITableViewCell 的 imageView 适合 40x40 [英] UITableViewCell's imageView fit to 40x40

查看:17
本文介绍了UITableViewCell 的 imageView 适合 40x40的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 tableView 和 detailView 中使用相同的大图像.当在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆