Swift and Xcode - How to Create Custom Tab Bar Icons

后端 未结 4 1935
太阳男子
太阳男子 2021-01-30 11:34

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

4条回答
  •  时光说笑
    2021-01-30 11:56

    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. 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)

    In Xcode I did the following:

    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).

    Done.

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

提交回复
热议问题