在UIActionSheet中自定义按钮,可以通过以下方法实现:
let actionSheet = UIActionSheet(title: "自定义按钮", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: "按钮1", "按钮2", "按钮3")
actionSheet.actionSheetStyle = .default
actionSheet.setTitle("自定义按钮", forButtonAt: 0)
actionSheet.setTitleColor(.red, for: .normal)
func actionSheet(_ actionSheet: UIActionSheet, clickedButtonAt buttonIndex: Int) {
switch buttonIndex {
case 0:
print("点击了按钮1")
case 1:
print("点击了按钮2")
case 2:
print("点击了按钮3")
default:
break
}
}
actionSheet.show(in: self.view)
通过以上方法,可以在UIActionSheet中自定义按钮的标题、颜色和样式,并实现按钮点击事件。
领取专属 10元无门槛券
手把手带您无忧上云