在单元格cell中快速简单创建圆角/圆形的的图片imageView

来源:互联网 发布:大型数据机房施工方案 编辑:程序博客网 时间:2024/05/17 00:16

有时显示cell的图片会有圆角或者圆形的需求,具体代码如下,可根据自己对圆角半径的大小需求做相应数值的调整:

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

{

    staticNSString *addressCellDentifier = @"addressCell";

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:addressCellDentifier];

    if (cell ==nil) {

         cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:addressCellDentifier];

        cell.imageView.frame =CGRectMake(0.0,0.0, 60.0,60.0);

        // 圆角cell

        CALayer *cellImageLayer = cell.imageView.layer;

//        [cellImageLayer setCornerRadius:cell.imageView.frame.size.width / 2];

        [cellImageLayer setCornerRadius:23.0];

        [cellImageLayer setMasksToBounds:YES];

       cell.imageView.image = [UIImageimageNamed:@"你的图片名"];

    return cell;


    }


还有一种方法是在自定义cell的时候,重写它里面的父类方面, 代码会比较多,我就不说了.
0 0
原创粉丝点击