Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change tint color / font color of Done / Cancel buttons #54

Closed
nneuberger1 opened this issue Sep 23, 2014 · 16 comments
Closed

Change tint color / font color of Done / Cancel buttons #54

nneuberger1 opened this issue Sep 23, 2014 · 16 comments

Comments

@nneuberger1
Copy link

I'd like to change the font color of the text on the picker "Cancel" and "Done" buttons. How can they be changed directly.

My application typically has black menus with white text on the menu.

I'm calling the following:

[ActionSheetStringPicker showPickerWithTitle:@"A-Trapezoidal (A-Trap)" rows:self.atrapNamesArray initialSelection:0 target:self successAction:@selector(atrapWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:self.view];

I do have a workaround by calling this line of code, but it causes havoc elsewhere inside my app. i end up putting this in multiple locations and switching the UIColor to do it.

UIBarButtonItem *barButtonAppearance = [UIBarButtonItem appearance];
[barButtonAppearance setTintColor:[UIColor blackColor]];

I'd be fine with changing the background color as an alternative.

@skywinder
Copy link
Owner

Hi. There is no support to choose tint color yet.

@skywinder
Copy link
Owner

If you want to set custom tint color for buttons - you can implement your own buttons and replace default buttons with your own by methods: setCancelButton: and setDoneButton:

@rustanacexd
Copy link

+1 yeah this is a must have feature I think

@jruston
Copy link

jruston commented Jul 4, 2015

Also would very much appreciate this.

@skywinder skywinder reopened this Jul 4, 2015
@skywinder
Copy link
Owner

@rustanacexd , @jrustonapps ok, I reopen this issue, since there is at least 3 person mention about this.. I can't promise, that I will implement it in near future, but I'm open for a pull requests and you can implement this feature by yourself also. (as I mention above by methods: setCancelButton: and setDoneButton: )

@skywinder skywinder removed the question label Jul 4, 2015
@tobedev
Copy link

tobedev commented Jul 4, 2015

A working workaround you can use is to set a tint color to the main window that hosts the actionpicker, in the SWActionSheet.m file as follows:

- (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. This will set the tint color of the default buttons in every single instance of actionsheetpicker in your project.

@kivannc
Copy link

kivannc commented Aug 19, 2015

You can set the color for a single button by using setTitleTextAttiributes. Here is the example

    UIBarButtonItem *barButtonNext1 = [[UIBarButtonItem alloc]
                                       initWithTitle:NSLocalizedString(@"Next", nil)
                                       style:UIBarButtonItemStylePlain
                                       target:self
                                       action:@selector(genderNextTapped:element:)];

    [barButtonNext1 setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]} forState:UIControlStateNormal];
    [self.pickerGender setDoneButton:barButtonNext1];

@tbaranes
Copy link

+1, I'd love to have this feature too without to have override the native buttons.

@zerodiff
Copy link

For what it's worth, another workaround is to override this method from AbstractActionSheetPicker in whatever subclass of a subclass you can create to set whatever color you want:

- (UIBarButtonItem *)createButtonWithType:(UIBarButtonSystemItem)type target:(id)target action:(SEL)buttonAction
{
    UIBarButtonItem *barButton = [super createButtonWithType:type target:target action:buttonAction];
    barButton.tintColor = [UIColor whiteColor];
    return barButton;
}

This will keep the default button behavior but change the styles. Of course, you could also make a property of your subclass, etc. I know people are all about composition over inheritance, but hackers gotta hack.

In any case, this a very useful library and saves a lot of time.

@ghysrc
Copy link

ghysrc commented Nov 13, 2015

+1, I was just told to change the tint color.

@mathieudebrito
Copy link

+1

@Maxatma
Copy link

Maxatma commented Mar 29, 2016

ActionSheetStringPicker does not conform to the UIAppearanceContainer protocol
+1 would be nice have this protocol to set same colours for all pickers in app

@hanishassim
Copy link

+1

@skywinder
Copy link
Owner

Hooray, guys! Please welcome version 2.2.0. Now you can use toolbarButtonsColor to easily setup color of toolbar buttons! As well as toolbarBackgroundColor property to setup background color! 🎉

@mikecole20
Copy link

It would still be nice to set the font without having to override the button completely. If you do provide a custom button, do the doneBlock and cancel closures still get called? I ask because UIBarButtonItems ask for a target and action (a selector).

@tbaranes
Copy link

tbaranes commented Jan 20, 2017

Yes, you don't have to set a selector to your custom UIBarButtonItem if you have a doneBlock set
(same for cancel). The block will be called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests