iOS 8自定义UIActivity图像黑色背景颜色 [英] iOS 8 custom UIActivity image black background color
问题描述
我试图添加类型
UIActivityCategoryAction
的自定义 UIActivity
到 UIActivityController
。
有没有办法改变这个?
这里有 3件要注意:
- 图片背景,
- 图片不透明度,
- 图片尺寸。
$ b b
iOS 7 >
- 图片背景 / li>
图片背景应为透明。
- 图像不透明
图标的可见部分不透明。请注意,不会保留任何颜色信息 :
由于系统不会缩放图片太小/太大 ,您必须提供适当大小的图像。我发现图像大小 120px x 120px
以适合完美。
iOS 8 +
- 图片背景:
图片背景应为白色以匹配系统 UIAction
图标,但也可以使用任意颜色。
- 图片不透明度
与iOS 7相同,的图标应该是不透明的,但是在iOS 8+ 颜色信息将被保留。
- 图片大小
我使用图片大小 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:
- image background,
- image opaqueness,
- image size.
iOS 7
- Image background:
Image background should be transparent.
- image opaqueness
The "visible part" of the icon should be non transparent aka opaque. Note that any color information won't be preserved:
- 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+
- Image background:
Image background should be white to match the system UIAction
icons but you can also use an arbitrary color.
- 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.
- 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屋!