Swift 和 Xcode - 如何创建自定义标签栏图标 [英] Swift and Xcode - How to Create Custom Tab Bar Icons

查看:38
本文介绍了Swift 和 Xcode - 如何创建自定义标签栏图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Swift 编写的 Xcode 选项卡式应用程序项目(Xcode 6.3 和 Swift 1.2).我在使用自定义标签栏图标时遇到了很多麻烦.我在 Photoshop (CS6) 中设计了一个图像,将其保存为 PNG,在 Prepo 中将其大小调整为 30x30 并将其导入到资产库中的 Xcode 中.然后我将 tab view controllers 图标设置为该图像.但是,它没有显示出来.

I have a tabbed application project I am working on in Xcode written in Swift (Xcode 6.3 and Swift 1.2). I am having a lot of trouble with custom Tab Bar icons. I have designed an image in Photoshop (CS6), saved it as a PNG, resized it in Prepo to be 30x30 and imported it into Xcode in the asset library. I then set the tab view controllers icon to that image. However, it doesn't show up.

我查看了这些页面,但没有找到任何帮助:
https://www.youtube.com/watch?v=4qqqoAWNfZA自定义标签栏图标颜色http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=19333
http://www.appcoda.com/ios-programming-how-to-customize-tab-bar-background-appearance/https://www.youtube.com/watch?v=4Tj_SeApUrs

I have looked at these pages but not found any help:
https://www.youtube.com/watch?v=4qqqoAWNfZA Custom tab bar icon colors http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=19333
http://www.appcoda.com/ios-programming-how-to-customize-tab-bar-background-appearance/ https://www.youtube.com/watch?v=4Tj_SeApUrs

创建自定义标签栏图标的正确过程是什么?

What is the proper process to create custom tab bar icons?

推荐答案

经过一番研究,我解决了这个问题,所以我想我会在这里发帖,以防其他人有类似的问题.在 Photoshop 中,我做了以下操作:

After a bit of research I resolved the issue, so thought I'd post here in case anyone else has a similar issue. In Photoshop I did the following:

  1. 导入我想用作标签栏图标的图像(如果您使用黑白图像更容易,这样您就不必去除颜色).
  2. 将背景设置为透明"而不是白色.
  3. 从图像中删除所有白色,使其成为具有透明背景的黑色图像.
  4. 将图片保存为 .png.
  5. 将图像调整为正方形,尺寸为 75x75 像素(并命名为 imageName@3x.png)、50x50 像素(并命名为imageName@2x.png)和 25x25 像素(并命名为 imageName.png)
  1. Imported the image I wanted to use as the tab bar icon (its easier if you use a black and white image so that you don't have to remove colour).
  2. Set the background to 'Transparent' rather than white.
  3. Removed all white from the image so that it was just a black image with a transparent background.
  4. Saved the image as a .png.
  5. Resized the image to be a square with dimensions 75x75 pixels (and named imageName@3x.png), 50x50 pixels (and named imageName@2x.png), and 25x25 pixels (and named imageName.png)

在 Xcode 中我做了以下操作:

In Xcode I did the following:

  1. 将图片拖入Xcode,并将图片组重命名为icoImageName.
  2. 在 Xcode 的情节提要中选择了我想为其设置图像的选项卡,并将图像"(在检查器窗格中的条形项目"下)设置为 icoImageName.请注意,我没有在标签栏项目"下设置选定图像"(留空).
  1. Dragged the images into Xcode and renamed the image group as icoImageName.
  2. Selected the tab I wanted to set the image for in the storyboard in Xcode and set the 'Image' (under 'Bar Item' in the Inspector Pane) to icoImageName. Note that I did not set the 'Selected Image' under the 'Tab Bar Item' (leave this blank).

完成.

我希望这对某人有所帮助.也感谢大家的帮助.

I hope this helps someone. Thanks to everyone for their help as well.

这篇关于Swift 和 Xcode - 如何创建自定义标签栏图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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