ActionSheetStringPicker更改按钮颜色

时间:2017-01-29 20:39:09

标签: ios swift3

ActionSheetStringPicker.show(withTitle: "Select Status", rows: pickerData, initialSelection: self.selectedStatusRow, doneBlock: {
                        picker, value, index in                  
                        self.selectedStatusRow = value                                    
                        return
                    }, cancel: { ActionStringCancelBlock in return }, origin: sender)

我想要的是在使用这个库时更改swift 3中取消和完成按钮的颜色。这怎么办?我需要它来采取我的主题,以及我拥有的全球色调。谢谢你

3 个答案:

答案 0 :(得分:1)

我正在搜索一些示例来本地化默认取消和完成按钮,下面是示例代码,用于自定义ActionSheetPicker-3.0的默认取消和完成工具栏按钮

 @IBAction func showCompanyTypes(_ sender: Any) {

    let cancelButton:UIButton =  UIButton(type: .custom)
    cancelButton.setTitle("Cancel", for: .normal)
    cancelButton.setTitleColor(UIColor.black, for: .normal)
    cancelButton.frame = CGRect(x: 0, y: 0, width: 55, height: 32)

    let doneButton:UIButton =  UIButton(type: .custom)
    doneButton.setTitle("Done", for: .normal)
    doneButton.setTitleColor(UIColor.black, for: .normal)
    doneButton.frame = CGRect(x: 0, y: 0, width: 55, height: 32)

    let acp = ActionSheetStringPicker(title: "Company Type", rows: ["Private Sector", "Government", "Semi Government", "Free Zone"], initialSelection: 0, doneBlock: {
        picker, values, indexes in

        print("values = \(values)")
        print("indexes = \(indexes)")
        print("picker = \(picker)")

        return

    }, cancel: { ActionMultipleStringCancelBlock in return }, origin: sender)


    acp?.pickerTextAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 15.0)]
    acp?.setTextColor(UIColor.black)
    acp?.pickerBackgroundColor = UIColor.white
    acp?.toolbarBackgroundColor = UIColor.white
    acp?.toolbarButtonsColor = UIColor.black
    acp?.setCancelButton(UIBarButtonItem(customView: cancelButton))
    acp?.setDoneButton(UIBarButtonItem(customView: doneButton))
    acp?.show()

}

答案 1 :(得分:0)

答案 2 :(得分:0)

您可以使用的工作解决方法是在SWActionSheet.m文件中为托管操作选择器的主窗口设置色调颜色,如下所示:

- (UIWindow *)window {

    if ( SWActionSheetWindow )
    {
        return SWActionSheetWindow;
    }
    else
    {
        return SWActionSheetWindow = ({
            UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
            window.windowLevel        = UIWindowLevelAlert;
            window.backgroundColor    = [UIColor clearColor];

            // Window Tint Color.
            [window setTintColor:[UIColor whatEverColor]];

            window.rootViewController = [SWActionSheetVC new];
            window;
        });
    }
}

PS。这将在项目中的actionsheetpicker的每个实例中设置默认按钮的色调颜色。

来源:https://github.com/skywinder/ActionSheetPicker-3.0/issues/54