UIActivityViewController with custom UIActivity displays color image as gray

人盡茶涼 提交于 2019-11-26 21:48:04

问题


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

回答1:


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

- (UIImage *)_activityImage {}

You lose the rounded grey bounding box though




回答2:


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;
}



回答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.




回答4:


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.



来源:https://stackoverflow.com/questions/20891730/uiactivityviewcontroller-with-custom-uiactivity-displays-color-image-as-gray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!