Is it possible to change UIPreviewAction color?
Asked Answered
H

4

9

The only options for styling I saw in the API are:

  • UIPreviewActionStyleDefault
  • UIPreviewActionStyleSelected,
  • UIPreviewActionStyleDestructive

Is it possible to somehow paint the buttons in another color? Our designer really didn't liked the default blue buttons

Hospodar answered 2/9, 2016 at 15:19 Comment(1)
I think it is answered hereTaxidermy
H
3

No, it is not possible to change button colors in UIPreviewAction. Even if you add colored images it will switch to default blue color.

Hatching answered 15/3, 2017 at 11:47 Comment(0)
T
3

Try this:

myPreviewAction.tintColor = myColor

With this UIPreviewAction extension:

extension UIPreviewAction {

    var tintColor: UIColor? {
        get {
            return value(forKey: "_color") as? UIColor
        }
        set {
            setValue(newValue, forKey: "_color")
        }
    }

}
Thirtyone answered 20/9, 2017 at 9:4 Comment(0)
S
1

You can add these snippets on below for the viewcontroller which implements UIPreviewAction

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    UIView *containerView = [self.view superviewOfClass:NSClassFromString(@"_UIVisualEffectContentView")];
    containerView.tintColor = YOUR_CUSTOM_COLOR;
}

In a UIView category

- (UIView *)superViewOfClass:(Class)class {
    UIView *parent = self;
    while ((parent = parent.superview)) {
        if ([parent isKindOfClass:class]) {
            return parent;
        }
    }
    return nil;
}
Saying answered 14/3, 2017 at 19:22 Comment(1)
Yeah, I think i prefer not using these kind of solutions. Too easy to break with iOS updates. But thank youHospodar
A
1

You can only for UIPreviewActionStyleDefault by setting global tint color:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self.window setTintColor:[UIColor greenColor]];
    return YES;
} 
Ardis answered 3/5, 2018 at 14:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.