2013-04-19 20 views
8

ちょっとすべて私が設定しようとしているのはcell.imageViewcornerRadiusですが、動作していないようです。iOS UITableViewCell cell.imageView角を丸く設定した

cell.imageView.layer.cornerRadius=9; 

それは動作しますか私は、丸みを帯びた角を持つように私のセルにカスタムUIImageViewを追加する必要がありますか?

また、私はこの

cell.imageView.layer.borderWidth=2; 
cell.imageView.layer.borderColor=[[UIColor blackColor]CGColor]; 

をしようとしたが、それも動作するようには思えません。誰も似たような問題に直面していますか?

+4

をあなたが設定する必要があります'masksToBounds'も同様です。 'CALayer'のドキュメントを読んだことがありますか? – Desdenova

+0

@Desdenova申し訳ありませんが、基本的なことを忘れてしまいました。 – satheeshwaran

答えて

27

まずadd Framework - プロジェクトへ> QuartzCore.framework
その後、あなたのViewController.mファイルにインポートヘッダファイル

#import <QuartzCore/CALayer.h> 

は、あなたのcellForRowAtIndexPathメソッドで次のコードを追加します。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSString *cellIdentifier = @"TableViewCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 

     // Rounded Rect for cell image 
     CALayer *cellImageLayer = cell.imageView.layer; 
     [cellImageLayer setCornerRadius:9]; 
     [cellImageLayer setMasksToBounds:YES]; 
    }         

    cell.imageView.image = [UIImage imageNamed:@"image_name.png"]; 

    return cell; 
} 
+3

ありがとう、私はsetMasksToBoundsを見逃しました。ひどい間違いをした。 – satheeshwaran

関連する問題