ios - 如何将图像添加到 ios 中 uicollectionView 单元格的左上角?

标签 ios objective-c iphone ipad uibutton

我想在 UICollectionViewCell 的左上角添加按钮。我可以在单元格的左上角添加按钮,但它不会出现在单元格的顶部,而是出现在单元格的下方。请告诉我该怎么做?

我正在使用以下代码:
enter image description here

_deleteButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, delButtonSize, delButtonSize)];
    _deleteButton.center = CGPointMake(9, 10);
    _deleteButton.backgroundColor = [UIColor clearColor];

    [_deleteButton setImage: [UIImage imageNamed:@"cross_30.png"] forState:UIControlStateNormal];
    [cell addSubview:_deleteButton];

    [_deleteButton addTarget:self action:@selector(deleteRecipe:) forControlEvents:UIControlEventTouchUpInside];

编辑:
我想做这样的删除图标:
enter image description here

最佳答案

您是否尝试将其添加到单元格的内容 View 中? [cell.contentView addSubview:_deleteButton];

关于ios - 如何将图像添加到 ios 中 uicollectionView 单元格的左上角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33580589/

相关文章:

ios - AFNetworking Reachability 第一次无法识别互联网连接

iphone - 使用 RESTKit 解析深层 XML 结构

ios - 为什么 iOS 在应用更新时会得到一个新的 identifierForVendor?

ios - 如何找到此系统警报的 UI View ?

ios - 当使用相同坐标绘制的图像形成圆弧时,CGRect 中绘制的文本标签形成椭圆弧

objective-c - 如何检查控件是否正在退出第一响应者或成为第一响应者?

ios - swiftyJSON 检查值是否为空

objective-c - 将 char 输入复制到字符串数组中

iphone - iPhone OS > 用户界面的 Window XIB 和 View XIB 模板之间的区别在哪里?

ios - iPhone 11 空白导航菜单