Swift和Xcode - 如何创建自定义选项卡栏图标 [英] Swift and Xcode - How to Create Custom Tab Bar Icons
问题描述
我有一个标签式应用程序项目,我正在使用Swift编写的Xcode( Xcode 6.3和Swift 1.2
)。我在使用自定义标签栏图标时遇到了很多麻烦。我在Photoshop(CS6)中设计了一个图像,将其保存为PNG,在Prepo中将其调整为 30x30
并将其导入资产库中的Xcode。然后,我将选项卡视图控制器
图标设置为该图像。但是,它没有出现。
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
b $ b 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?
推荐答案
经过一段时间的r esearch我解决了这个问题,所以我想在这里发帖以防其他人有类似的问题。在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:
- 导入我想用作标签栏图标的图像(如果你使用黑色和白色图像,以便您不必删除颜色。)
- 将背景设置为透明而不是白色。
- 删除所有白色从图像中,它只是一个透明背景的黑色图像。
- 将图像保存为.png。
- 将图像调整为是一个尺寸
75x75像素的广场
(并命名为imageName@3x.png
),50x50像素
(并命名为imageName@2x.png
),25x25像素
(并命名imageName.png
)
- 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).
- Set the background to 'Transparent' rather than white.
- Removed all white from the image so that it was just a black image with a transparent background.
- Saved the image as a .png.
- Resized the image to be a square with dimensions
75x75 pixels
(and namedimageName@3x.png
),50x50 pixels
(and namedimageName@2x.png
), and25x25 pixels
(and namedimageName.png
)
在Xcode中,我做了以下内容:
In Xcode I did the following:
- 将图像拖动到Xcode中,并将图像组重命名为
icoImageName
。 - 在Xcode的故事板中选择我想要设置图像的选项卡并设置'Image '(在Inspector窗格中的'Bar Item'下)到
icoImageName
。请注意,我没有在'Tab Bar Item'下设置'Selected Image'(留空)。
- Dragged the images into Xcode and renamed the image group as
icoImageName
. - 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屋!