9

を設定しようとしてcell.imageViewcornerRadiusますが、うまくいかないようです。

cell.imageView.layer.cornerRadius=9;

UIImageViewそれは機能しますか、それとも角を丸くするためにセルにカスタムを追加する必要がありますか?

私もこれを試しました

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

しかし、それもうまくいかないようです。誰かが同様の問題に直面しましたか?

4

1 に答える 1

28

最初に 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;
}
于 2013-04-19T11:46:45.800 に答える