What size should TabBar images be?
30x30 is points, which means 30px @1x, 60px @2x, not somewhere in-between. Also, it's not a great idea to embed the title of the tab into the image—you're going to have pretty poor accessibility and localization results like that.
Tab Bar Icon Size
You should not do this yourself system can do it automatically.
here is Apple Human Interface Guidelines, where you can find icon resolutions:
https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/custom-icons/
for example:
If you are using circular icons for tab bar item you should create following sizes for portrait mode:
- 75px × 75px (25pt × 25pt @3x)
- 50px × 50px (25pt × 25pt @2x)
- 25px × 25px (25pt × 25pt @1x)
and for landscape mode:
- 54px × 54px (18pt × 18pt @3x)
- 36px × 36px (18pt × 18pt @2x)
- 18px × 18px (18pt × 18pt @1x)
after you add this icons into Assets.xcassets or somewhere, you can select Tab Bar Item icons from storyboard:
select Tab Bar item and in the attributes inspector, choose portrait image for image field, and landscape image for landscape field.
After that system will do everything for you.
TabBarItems and setting their image sizes?
You should prepare 3 images icons for each tab bar item (1x, 2x and 3x).
First create the 3x at 75w 75h pixels (maximum: 144 x 96) and save it as iconTab0@3x.png.
Then resize it to 50w 50h pixels (maximum: 96 x 64) and save it as iconTab0@2x.png.
Finally resize it to 25w 25h pixels (maximum: 48 x 32) and save it as iconTab0.png.
Now all you need is to select those 3 images at your finder and drag them to your image assets.
Human Interface Guidelines
Tab Bar icons too small despite being correct size
Image icons of 75x75 px should be fine for @3x devices.
If the title is nil, image will not expand on itself.
However you can shift the image using offset property.
Go to Size Inspector in storyBoard, and change image inset's Bottom offset.
Refer to this link for more info
Moving UITabBarItem Image down?
What size should my tab bar item icons be?
There is only one size being specified in that document for tab bar items - 25x25. The other two are simply 2x and 3x variants - not per device but per screen resolution. Thus the way to do this is the same way we've always done it for images in general. Use the asset catalog or use the @2x
and @3x
name suffixes. (I prefer the asset catalog; it doesn't get any easier.)
What are the correct dimensions for a custom tab bar item background image?
Making my answer for this question how to make UITabBar selection indicator image fill the whole space? as reference:
Subclass the UITabBarController
It works for multiple devices even with rotation.
Notes:
- Make your images' rendering mode as
Original
. Assign this class below to your UITabBarController in your Storyboard or as your base class if you're doing your screen programmatically.
//
// BaseTabBarController.swift
// MyApp
//
// Created by DRC on 1/27/17.
// Copyright © 2017 PrettyITGirl. All rights reserved.
//
import UIKit
class BaseTabBarController: UITabBarController {
let numberOfTabs: CGFloat = 4
let tabBarHeight: CGFloat = 60
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateSelectionIndicatorImage()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
updateSelectionIndicatorImage()
}
func updateSelectionIndicatorImage() {
let width = tabBar.bounds.width
var selectionImage = UIImage(named:"myimage.png")
let tabSize = CGSize(width: width/numberOfTabs, height: tabBarHeight)
UIGraphicsBeginImageContext(tabSize)
selectionImage?.draw(in: CGRect(x: 0, y: 0, width: tabSize.width, height: tabSize.height))
selectionImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
tabBar.selectionIndicatorImage = selectionImage
}
}
Related Topics
Cfbundleversion Must Be Higher Than Previous Version
Facebook Sdk 3.1 for iOS - Runs on iOS6, But Crashes on iOS 5.X
How to Use Objective-C Blocks as Properties
How to Access Files in Icloud Drive from Within My iOS App
How to Programmatically Increase Uitableview Cell's Height in Iphone
Calculate Total Traveled Distance iOS Swift
Downloading Uiimage via Alamofireimage
Performseguewithidentifier Very Slow When Segue Is Modal
Nehotspothelper Annotations Not Appearing
Default Tab Bar Item Colors Using Swift Xcode 6
How to Add Uipickerview into Uialertcontroller (Alert or Actionsheet) in Swift
Uitextviews in a Uitableview Link Detection Bug in iOS 7
Method Load() Defines Objective-C Class Method 'Load', Which Is Not Permitted by Swift 1.2
How to Create Auto Incremented Key in Firebase