2011-12-29 23 views
2

我想有uiimagview與該代碼tableviewcell已圓角:如何圓一個UIImageView的courners在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; 
} 

但圖像顯示爲空白的tableViewCells當我運行。

它工作正常,如果我只是做cell.imageView.image = [[ImageCache sharedImageCache] imageForKey:possession.imageKey];(但沒有圓角)

我在做什麼錯?

+0

細胞.imageView = [roundedImage圖像];嘗試這個。 – Sarah 2011-12-29 05:25:14

+0

錯誤:自動引用計數問題:實例消息的接收器類型'UIImageView'沒有聲明具有選擇器'Image'的方法 – ladookie 2011-12-29 05:27:59

+0

檢查UIImage *圖像是否分配了內存? – Sarah 2011-12-29 05:43:09

回答

10

你需要使用石英框架。這裏是一個轉彎和添加邊框圖像的代碼

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

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

第一組圖像,以imageview的,然後更改的ImageView層

+0

但我有'#import ' – ladookie 2011-12-29 05:32:52

+0

你能看到沒有「角落」代碼的圖像。什麼是你設置的圖像的尺寸 – 2011-12-29 06:08:42

+1

啊這工作,顯然我只需要在更改imageview圖層之前先設置圖像。 – ladookie 2011-12-29 06:10:28

1

使用

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

還實現

<QuartzCore/QuartzCore.h> 
相關問題