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

Paulo Cesar
  • 2,250
  • 1
  • 25
  • 35

4 Answers4

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.

Arpit Jain
  • 1,660
  • 12
  • 23
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")
        }
    }

}
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;
}
abdullahselek
  • 7,893
  • 3
  • 50
  • 40
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;
} 
Di B.
  • 1,009
  • 10
  • 11