CooperRS / RMActionController

This is an iOS control for presenting any UIView in an UIAlertController like manner
MIT License
539 stars 59 forks source link

Unable to change the tintColor of Cancel button #26

Closed d-shenoy closed 7 years ago

d-shenoy commented 7 years ago

Hi, Thank you for all your hard work. This is an awesome tool. I was wondering if you can help me with this issue. I want to change the color of the Cancel button to be red and yet keep it as a "Cancel" style. Is this possible.?

Thanks

CooperRS commented 7 years ago

Hi there,

This is possible using a subclass of RMAction. Internally, RMAction initialises a UIView (see -[RMAction loadView]). Just write your own subclass of RMAction and overwrite this method to return the UIView you want to have :)

dazzyjong commented 7 years ago

Even I change [RMAction loadView] to show ios 10 default button( blue color ), but the button color is gray only. Please give advice.

` UIButton *actionButton = [UIButton buttonWithType:UIButtonTypeSystem];

[actionButton setTitleColor:[UIColor colorWithRed:0/255 green:122/255 blue:255/255 alpha:1] forState:UIControlStateNormal];
[actionButton addTarget:self action:@selector(actionTapped:) forControlEvents:UIControlEventTouchUpInside];

if(self.title) {
    [actionButton setTitle:self.title forState:UIControlStateNormal];
}

[actionButton addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[actionButton(height)]" options:0 metrics:@{@"height": @([NSProcessInfo runningAtLeastiOS9] ? 55 : 44)} views:NSDictionaryOfVariableBindings(actionButton)]];

return actionButton;

`

phinguyenterralogic commented 7 years ago

I hope that will help you

import UIKit
import RMActionController

class RMActionCustom: RMAction<UIView> {
    var btnView : UIButton?
    override func loadView() -> UIView {
        btnView = super.loadView() as? UIButton
        btnView?.setTitleColor(UIColor.red, for: .normal)
        return btnView!
    }
}
CooperRS commented 7 years ago

This is fixed by #31: Set RMActionController.disableBlurEffectsForActions to YES and use the appearance of the button to set the tint color:

[[UIButton appearance] setTintColor:<Your UIColor here>];