UIActivityViewController with custom UIActivity displays color image as gray

6.8k views Asked by At

I created a custom UIActivity to display in a share sheet. I created an 60x60 icon (png file) in full color, but when it's displayed it only shows the outline in gray. I don't see what I've written incorrectly. I hope someone sees what I've missed. Any help will be greatly appreciated. Here is my code...

@implementation MyActivity

#pragma mark - Overrides
- (NSString *)activityType {
    return @"MyType";
}

- (NSString *)activityTitle {
    return @"ShareMe";
}

- (UIImage *)activityImage {
    return [UIImage imageNamed:@"MyIcon_60x60.png"];
}

- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
    return YES;
}

- (void)prepareWithActivityItems:(NSArray *)activityItems {
    // Do Something
}

+ (UIActivityCategory)activityCategory {
    return UIActivityCategoryShare;
}

@end
4

There are 4 answers

3
Ryan Berg On BEST ANSWER

Try adding an underscore to the method in the subclassed UIActivity class

- (UIImage *)_activityImage {}

You lose the rounded grey bounding box though

1
Matt Morey On

Unfortunately that is the way it is supposed to work. The Apple Docs state:

The alpha channel of the image is used as a mask to generate the final image that is presented to the user. Any color data in the image itself is ignored...

If you want to use a full color image you will have to replicate the behavior of the UIActivityViewController and add support for color images.

I recommend you look at Overshare as it supports full-color icons.

2
Tibidabo On

I'm not sure it's a bug or feature, but in iOS 8 if activityCategory is UIActivityCategoryShare it shows a nice rounded color icon. It shows a grey box in iOS 7. _activityImage looks a private API for me.

+ (UIActivityCategory)activityCategory {
    return UIActivityCategoryShare;
}
0
Paul On

In iOS 10, set the activityCategory class property of your UIActivity subclass to .share. This will cause the activity icon to appear in color in the top row of the UIActivityViewController.

In your UIActivity subclass:

class GroupMessageActivity: UIActivity
{
    ...

    override open class var activityCategory: UIActivityCategory
    {
        get
        {
            return UIActivityCategory.share;
        }
    }

    ...
}

The default value or UIActivityCategory.action uses the alpha channel to produce a grayscale image in the bottom "action" row.