【问题标题】:roundedCorner on UIImageView applies incorrectly to UITableCellUIImageView 上的 roundedCorner 错误地应用于 UITableCell
【发布时间】:2012-10-15 23:06:23
【问题描述】:

您好,我有一个表格单元格,其中包含一个 UIImageView。我想让这个 UIImageView 有一个圆角。这是我拥有的代码(相关的sn-ps):

UIImageView* image;
image = (UIImageView*)[cell viewWithTag:0]; // get the UIImageView from the nib
image.image = [UIImage imageWithData:imageData]; // imagedata contains the image
image.layer.cornerRadius = 10.0;
image.layer.masksToBounds = YES;
image.clipsToBounds = YES;

当我这样做时,整个 UITableViewCell 会得到圆角,而不是 UIImageView(见附图)。

谁能告诉我为什么圆角应用于表格单元格而不是 uiImageView?

http://i.stack.imgur.com/CnkyQ.png

【问题讨论】:

  • 因为您将圆角的东西设置为单元格,而不是图像。如果要设置图像“圆角”外观,则需要获取对图像的引用

标签: objective-c ios uitableview rounded-corners


【解决方案1】:

(UIImageView*)[cell viewWithTag:0];

cell 子视图中,您只有UITableViewCellContentViewtag == 0

您可以手动将 UIImageView 添加到单元格。

【讨论】:

  • 谢谢!就是这样 - 我最终从 NIB 中删除了 UIImageView 并创建了我自己的,并调用了 [cell addSubview:imageView];
【解决方案2】:

问题应该是...Tag:0:

image = (UIImageView*)[cell viewWithTag:0]; // get the UIImageView from the nib

如果您使用的是非自定义 UITableViewCell,请将该行替换为:

image = (UIImageView*)[cell imageView];

否则,替换标签号。

【讨论】:

    猜你喜欢
    • 2016-04-10
    • 1970-01-01
    • 2017-05-15
    • 2019-02-27
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多