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
Rob
  • 4,149
  • 5
  • 34
  • 48

4 Answers4

33

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

- (UIImage *)_activityImage {}

You lose the rounded grey bounding box though

Ryan Berg
  • 1,761
  • 1
  • 13
  • 9
  • 15
    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... – tomwilson Mar 28 '14 at 03:42
  • Hi, really thank you so much its working fine for me, But i don't how its working, Just changing underscore( _ ). – Vinayak Apr 18 '16 at 10:20
  • @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. – Surjeet Rajput Jun 23 '17 at 08:54
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;
}
Tibidabo
  • 21,461
  • 5
  • 90
  • 86
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.

Matt Morey
  • 984
  • 1
  • 11
  • 14
  • 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. – Rob Jan 02 '14 at 23:22
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.

Paul
  • 11
  • 4