gpt4 book ai didi

ios - UITableView 自定义单元格 - 如何将 cornerRadius 保持在编辑模式

转载 作者:搜寻专家 更新时间:2023-11-01 05:37:19 24 4
gpt4 key购买 nike

我实现了一个带有自定义单元格的表格 View 。单元格的 cornerRadius 设置为 2。在我进入编辑模式之前,一切都显示得很好。当删除按钮出现时,它的圆角半径为0。

如何让删除按钮也有一个角半径?

我尝试过这个但没有任何运气:

func tableView(tableView: UITableView, willBeginEditingRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
cell!.editingAccessoryView?.layer.cornerRadius = 2
}

enter image description here

拐角半径目前在我的 Storyboard中设置为用户定义的运行时属性。

enter image description here

最佳答案

你可以像这样操作按钮:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
var button1 = UITableViewRowAction(style: .Default, title: "Delete", handler: { (action, indexPath) in
println("button1 pressed!")
})


UIGraphicsBeginImageContext(button1.view.frame.size);
[[UIImage imageNamed:@"image.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

button1.view.backgroundColor = [UIColor colorWithPatternImage:image];

return [button1]
}

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
}

关于ios - UITableView 自定义单元格 - 如何将 cornerRadius 保持在编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35442819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com