UIActivityViewController with custom UIActivity displays color image as gray
Asked Answered
K

4

11

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
Kinesthesia answered 2/1, 2014 at 20:57 Comment(2)
have you found any solution i am also facing the same issue? Any help will be highly appreciated.Pneumo
The answer below is the only thing I've found.Kinesthesia
R
33

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

- (UIImage *)_activityImage {}

You lose the rounded grey bounding box though

Reconstructive answered 26/3, 2014 at 18:56 Comment(3)
Yeah, this totally works - have you tried to get it through Apples approval process though? It's a private API but maybe you can sneak it through...Sisyphean
Hi, really thank you so much its working fine for me, But i don't how its working, Just changing underscore( _ ).Schappe
@BrandonA override activityImage method of UIActivity to display images.As per apple Action image should be grayscale image if its colored it will displayed as grayscla image.Numerate
C
7

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;
}
Conure answered 25/5, 2015 at 6:4 Comment(2)
here's a more detailed sol. about activityCategory: https://mcmap.net/q/758540/-how-can-i-add-a-activityitem-to-upper-activity-bar-in-uiactivityviewcontrollerMeandrous
This is the correct solution, the _activityImage maybe can cause a rejection from apple?Ischia
A
3

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.

Am answered 2/1, 2014 at 22:36 Comment(1)
Thank you for the information, I read through that paragraph and that sentence didn't register. It's a shame about the color. Unless I spend a lot of time reinventing the wheel, I will not be able to display a color icon like YouTube's red icon.Kinesthesia
J
0

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.

Jalopy answered 14/1, 2017 at 4:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.