【问题标题】:UITableViewCell circle imageviewUITableViewCell 圆形图像视图
【发布时间】:2016-04-02 09:23:12
【问题描述】:

我有一个UITableViewUITableViewCell,我想将cell.imageView作为圈子。所以我在我的cellForrowAtIndex 中做到了这一点

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];


    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];




    }

    cell.backgroundColor=[UIColor clearColor];

    cell.imageView.layer.cornerRadius=cell.imageView.frame.size.width/2;
    cell.imageView.layer.masksToBounds=YES;
    cell.imageView.layer.borderWidth = 2.0f;
    cell.imageView.layer.borderColor=[UIColor whiteColor].CGColor;

但是当加载表格时UIImages 是正方形,然后当我滚动它时它变成了圆圈。我怎么解决这个问题? 请帮我。 谢谢

【问题讨论】:

    标签: ios objective-c uitableview uiimageview


    【解决方案1】:

    下面是代码

    [cell.imgview setImage:[UIImage imageWithData:imgData]];
    cell.imgview.layer.cornerRadius = cell.img_userpic.frame.size.height /2;
    cell.imgview.layer.masksToBounds = YES;
    cell.imgview.layer.borderWidth = 0;
    

    您的 Imageview 的宽度和高度应该相同,否则它不会显示圆形。

    【讨论】:

      【解决方案2】:

      您需要通过继承UITableViewCell 创建一个自定义单元格,然后在该类中配置单元格。

      在其中实现awakeFromNib 方法,并在此方法中根据需要设置图像视图。

      【讨论】:

        【解决方案3】:

        在你的 cellForRow 方法中使用下面的代码行。对于圆形,您必须设置图层的角半径并将 clipsToBounds 属性设置为YES

          cell.imageView.clipsToBounds = YES;
        

        【讨论】:

        • 不,它仍然一样,当加载所有方块时,只有滚动时它们变成圆圈
        • 写过cell.imageView.clipsToBounds = YES;在 cellfor Row 方法中?
        【解决方案4】:

        试试这个代码

        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(-30, 40, 100, 100)];
                imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
                imageView.layer.masksToBounds = YES;
                imageView.layer.cornerRadius = 50.0;
                imageView.layer.shadowRadius=5;
                imageView.layer.shadowOpacity=4;
                imageView.layer.shadowColor=(__bridge CGColorRef)([UIColor blackColor]);
                imageView.layer.borderColor = [UIColor whiteColor].CGColor;
                imageView.layer.borderWidth = 3.0f;
                imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;
                imageView.layer.shouldRasterize = YES;
                imageView.clipsToBounds = YES;
        

        【讨论】:

          猜你喜欢
          • 2018-10-26
          • 1970-01-01
          • 1970-01-01
          • 2021-03-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多