iOS 8自定义UIActivity图像黑色背景颜色 [英] iOS 8 custom UIActivity image black background color

查看:327
本文介绍了iOS 8自定义UIActivity图像黑色背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图添加类型 UIActivityCategoryAction 的自定义 UIActivity UIActivityController



有没有办法改变这个?

解决方案

这里有 3件要注意:


  1. 图片背景,

  2. 图片不透明度,

  3. 图片尺寸。


$ b b




iOS 7 >


  1. 图片背景 / li>

图片背景应为透明。


  1. 图像不透明

图标的可见部分不透明。请注意,不会保留任何颜色信息



由于系统不会缩放图片太小/太大 ,您必须提供适当大小的图像。我发现图像大小 120px x 120px 以适合完美。








iOS 8 +




  1. 图片背景

图片背景应为白色以匹配系统 UIAction 图标,但也可以使用任意颜色。


  1. 图片不透明度

与iOS 7相同,的图标应该是不透明的,但是在iOS 8+ 颜色信息将被保留


  1. 图片大小

我使用图片大小 240px x 240px ,但您可以应用自定义尺寸的图片,因为如果太小/太大,系统会自动填充图片






换行



也就是说,如果你想同时支持iOS 7和iOS 8+必须拥有自定义 UIActivity 图标图片的两个版本。



对于 iOS 7 应使用 120像素x 120像素大小的图片(透明背景)。 iOS 8 + ,您应该使用



代码示例 strong>

   - (UIImage *)activityImage 
{
if([[[UIDevice currentDevice] systemVersion ] floatValue]> = 8.0){
return [UIImage imageNamed:@activity_icon_ios8];
}
else {
return [UIImage imageNamed:@activity_icon];
}
}

希望有所帮助!


I am trying to add a custom UIActivity of type UIActivityCategoryAction to UIActivityController. But in iOS 8, all of them are appearing with a black background.

Is there a way to change this?

解决方案

There are 3 things to note here:

  1. image background,
  2. image opaqueness,
  3. image size.


iOS 7

  1. Image background:

Image background should be transparent.

  1. image opaqueness

The "visible part" of the icon should be non transparent aka opaque. Note that any color information won't be preserved:

  1. image size

Because the image won't be scaled by the system if too small/big, you have to provide appropriately sized image. I found image size 120px x 120px to fit perfectly.

Note: this size also takes icon padding into account.


iOS 8+

  1. Image background:

Image background should be white to match the system UIAction icons but you can also use an arbitrary color.

  1. image opaqueness

Same as in iOS 7, "visible" part of the icon should be non transparent aka opaque, however in iOS 8+ color information will be preserved.

  1. image size

I am using image with size 240px x 240px, but you can apply custom sized image because system will automatically scalle-to-fill image if too small/big.


Wrap up

That said, if you want to support both iOS 7 and iOS 8+, you have to have 2 versions of custom UIActivity icon image.

For iOS 7 you should use 120px x 120px sized image with transparent background. Note: find the size that best suits your needs.

For iOS 8+ you should use custom sized square image with white background and "visible" part of an arbitrary colour.

Code example

- (UIImage *)activityImage
{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        return [UIImage imageNamed:@"activity_icon_ios8"];
    }
    else {
        return [UIImage imageNamed:@"activity_icon"];
    }
}

Hope that helps!

这篇关于iOS 8自定义UIActivity图像黑色背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆