在 Xcode 7.2 中将 PDF 用于图标图像 [英] Using PDFs for icon images in Xcode 7.2

查看:24
本文介绍了在 Xcode 7.2 中将 PDF 用于图标图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 PDF 文件用作我正在开发的应用程序中的图标.我遇到的问题是色调不一致.

如果我从界面生成器设置按钮图像,图标图像在运行时显示为黑色.每次.无论我尝试从界面构建器设置什么.

我尝试通过代码设置我的按钮图标图像,不是显示黑色,而是白色:

let myGraphicFile = UIImage(named: "myPDFImage")让 myButtonImage = myGraphicFile?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)myButton.setImage(myButtonImage, forState: .Normal)

从代码中,无论我尝试将色调设置为什么,代码中始终是白色的.

我发现了这篇与 Xcode 6.x 相关的帖子,但我认为它可能已经过时了,因为我可以部分完成它,但我无法设置色调.

一旦它在那里配置,那么你就可以像对待界面构建器中的任何其他图像一样对待它.它本质上与我在代码中所做的事情相同,但我不认为它是在代码中完成的……它必须在图像所在的 xcAssets 上完成.我的理解是 iOS 在运行时为大小类渲染矢量图像.我认为尝试在代码中对其进行调整是行不通的,因为图像已经呈现.

如果有人对此有任何疑问,我发现了 this链接 有助于解决我的问题.

此外,这篇文章也涵盖了这个主题.https://stackoverflow.com/a/25804358/4475605

I'm attempting to use PDF files as icons in an app I'm working on. The issue I'm encountering is I'm getting inconsistent tint colors.

If I set a button image from interface builder, the icon image shows up black at runtime. Every time. Regardless of what I attempt to set from interface builder.

I tried setting my button icon image via code and instead of showing up black, it's white:

let myGraphicFile = UIImage(named: "myPDFImage")
let myButtonImage = myGraphicFile?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
myButton.setImage(myButtonImage, forState: .Normal)

From code, regardless of what I attempt to set the tint to, it's always white from code.

I discovered this post relating to Xcode 6.x, but I think it might be dated, as I'm able to partially do it, but I can't set the tint.

Use PDF in XCode for an AppIcon (.appiconset collection)

I create the icons in Inkscape, save as PDF 1.5. I add the file to Images.xcassets. In Images.xcassets' attributes inspector, I'm setting:

Devices to Universal

Scale factor to Single Vector.

Summary: I can get it to show up and scale properly, but it's either black from interface builder or white from code. I suspect I'm missing something re: how to save the file from Inkscape.

Thank you for reading. If you have any suggestions, I welcome them.

解决方案

I have figured out how to create vector icons with Inkscape. When you use PDFs to display icons in iOS, you need to alter the Attributes Inspector for your icon in xcAssets as follows:

1) Drag the PDF into xcAssets

2) Set devices (I did Universal and it worked fine)

3) If your PDF icon is under 1x, 2x, or 3x size class, drag it to Universal and delete the rest of them.

4) Set Scale Factors to Single Vector.

5) Render as Template Image.

Once it's configured there, then you just treat it was you would any other image in interface builder. It's essentially the same thing I was doing in code, but I don't think it gets done in code...it's gotta be done on xcAssets where the image lives. It's my understanding iOS renders vector images for the size class at run time. I think by attempting to tweak it in code wasn't working because the image had already been rendered.

If anyone has any questions on this, I found this link helpful in resolving my issue.

Additionally, this post covers the topic, too. https://stackoverflow.com/a/25804358/4475605

这篇关于在 Xcode 7.2 中将 PDF 用于图标图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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