如何在ActionSheet中更改某个按钮的颜色?

时间:2015-04-21 03:11:06

标签: ios swift uiactionsheet

var sheet: UIActionSheet = UIActionSheet()
        sheet.title  = "Report this member?"
        sheet.delegate = self
        sheet.tag = 1
        sheet.addButtonWithTitle("Cancel")
        sheet.addButtonWithTitle("Report")
        sheet.cancelButtonIndex = 0
        sheet.showInView(self.view)

我想"报告"变成红色,取消变成灰色。

有没有具体的方法来做到这一点?

1 个答案:

答案 0 :(得分:0)

您可以投放此广告,创建自定义按钮,将其添加为子视图

var sheet: UIActionSheet = UIActionSheet()
sheet.title  = "Report this member?"

var btn:UIButton = UIButton()
btn.setTitle("Cancel", forState: UIControlState.Normal)
btn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
btn.backgroundColor = UIColor.grayColor()
btn.addTarget(self, action: "pressCancel", forControlEvents: UIControlEvents.TouchDown)
sheet.addSubview(btn)

var btn1:UIButton = UIButton()
btn1.setTitle("Report", forState: UIControlState.Normal)
btn1.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
btn1.backgroundColor = UIColor.redColor()
btn1.addTarget(self, action: "pressReport", forControlEvents: UIControlEvents.TouchDown)
sheet.addSubview(btn1)
相关问题