在我的應用程序中,我自定義了我的TableViewCell
以顯示卡片。我還爲這些單元實施了自定義UITableViewRowActions
。然而,這些動作看起來很奇怪,因爲我添加了一個圖層來使單元格看起來像一張浮動卡片。如何調整UITableViewRowAction的大小以適應自定義大小的tableViewCell? - Swift 3
Here's what it looks like 這裏是我的代碼爲我的cellForRowAt
函數。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "someCell", for: indexPath) as! CustomCell
cell.delegate = self
cell.backgroundColor = .clear
cell.contentView.backgroundColor = .clear
let whiteRoundedView: UIView = UIView(frame: CGRect(x: 10, y: 8, width: self.view.frame.size.width - 20, height: cell.frame.size.height - 20))
whiteRoundedView.layer.backgroundColor = CGColor(colorSpace: CGColorSpaceCreateDeviceRGB(), components: [1.0, 1.0, 1.0, 0.9])
whiteRoundedView.layer.masksToBounds = false
whiteRoundedView.layer.cornerRadius = 2.0
whiteRoundedView.layer.shadowOffset = CGSize(width: -1, height: 1)
whiteRoundedView.layer.shadowOpacity = 0.2
cell.contentView.addSubview(whiteRoundedView)
cell.contentView.sendSubview(toBack: whiteRoundedView)
cell.updateCell()
return cell
}
和我的UITableViewRowAction
函數。預警:我用這SwipeCellKit庫
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
if orientation == .left {
guard isSwipeRightEnabled else { return nil }
let completeAction = SwipeAction(style: .default, title: "Complete") { (action, index) in
print("complete!")
}
completeAction.backgroundColor = .green
return [completeAction]
} else {
let deleteAction = SwipeAction(style: .destructive, title: "Delete") { (action, index) in
print("delete")
}
return [deleteAction]
}
}
有什麼辦法來調整UITableViewRowAction
以適應單元格的黴菌?
希望這個答案可以幫助你:http://stackoverflow.com/a/12511432/1931317 – Deepak