Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change UIPreviewAction color?

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

like image 773
Paulo Cesar Avatar asked Sep 02 '16 15:09

Paulo Cesar


3 Answers

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

like image 200
Arpit Jain Avatar answered Oct 12 '22 17:10

Arpit Jain


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")
        }
    }

}
like image 3
Emilio Cubo Ruiz Avatar answered Oct 12 '22 18:10

Emilio Cubo Ruiz


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;
}
like image 1
abdullahselek Avatar answered Oct 12 '22 18:10

abdullahselek