ActionSheetStringPicker更改按钮颜色

问题描述 投票:0回答:3
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中取消和完成按钮的颜色。这怎么办?我需要它来采取我的主题,以及我拥有的全球色彩。谢谢

ios swift3
3个回答
1
投票

我正在搜索一些示例来本地化Default Default和Done按钮,下面是示例代码,用于自定义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()

}


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

© www.soinside.com 2019 - 2024. All rights reserved.