简体   繁体   English

如何在tableViewCell中舍入UIImageView的courners

[英]How to round the courners of a UIImageView in a tableViewCell

I'm trying to have the uiimagview have rounded corners in a tableviewcell with this code: 我试图让uiimagview在tableviewcell中使用以下代码进行圆角处理:

#import <QuartzCore/QuartzCore.h>    
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomepwnerItemCell *cell = (HomepwnerItemCell *)[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];    

    Possession *possession = [self.possessions objectAtIndex:indexPath.row];
    cell.valueLabel.text = [@"$" stringByAppendingString:[[NSNumber numberWithInt:possession.valueInDollars] stringValue]];
    cell.nameLabel.text = possession.possessionName;

    UIImage *image = [[ImageCache sharedImageCache] imageForKey:possession.imageKey];      
    UIImageView *roundedImage = [[UIImageView alloc] initWithImage:image];
    roundedImage.layer.masksToBounds = YES;
    roundedImage.layer.cornerRadius = 10.0;
    cell.imageView = roundedImage;
    // cell.imageView.image = [[ImageCache sharedImageCache] imageForKey:possession.imageKey];
    return cell;
}

but the images show up blank in the tableViewCells when I run it. 但是当我运行它时,图像在tableViewCells中显示为空白。

it works fine if I just do cell.imageView.image = [[ImageCache sharedImageCache] imageForKey:possession.imageKey]; 如果我只做cell.imageView.image = [[ImageCache sharedImageCache] imageForKey:possession.imageKey];它工作正常 (but without the rounded corners) (但没有圆角)

What am I doing wrong? 我究竟做错了什么?

YOu need to use the quartz framework. 你需要使用石英框架。 Here is the code for cornering and adding border to image 这是转弯和添加边框到图像的代码

cell.imageView.layer.cornerRadius = 10.0;
cell.imageView.layer.borderColor = [UIColor blackColor].CGColor;

cell.imageView.layer.borderWidth = 1.2;
cell.imageView.clipsToBounds = YES;

First Set Image to imageview, then change the imageview layer 首先将图像设置为imageview,然后更改imageview图层

use 采用

cell.imageView.layer.cornerRadius=20;  //Use as ur specified corner length

also implement 也实施

  <QuartzCore/QuartzCore.h>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM