问题
I implemented a tableview with custom cells. The cells have their cornerRadius set to 2. Everything displays just fine until I enter edit mode. When the delete button appears, it's corner radius is 0.
How can I make the delete button have a cornerRadius too?
I tried this without any luck:
func tableView(tableView: UITableView, willBeginEditingRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)
cell!.editingAccessoryView?.layer.cornerRadius = 2
}
The corner Radius is currently set as a User Defined Runtime Attribute in my Storyboard.
回答1:
you can manipulate the button like this:
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) {
}
来源:https://stackoverflow.com/questions/35442819/uitableview-custom-cell-how-to-keep-cornerradius-in-edit-mode