Swift-Let the tab bar button uitabbaritem the picture centered (no text) _ Use

Source: Internet
Author: User
For the tab bar (Uitabbar), when the Tabbaritem does not need title as long as the image, the image below will occupy a space.
We can set the offset by tabbaritem.imageinsets so that the image icon is centered.

(Note: Top and bottom are set to the opposite number, otherwise the image size will change.) )

Import UIKit
Class MainTabViewController:UITabBarController
     Override func viewDidLoad()
         //A total of two views are included
         Let qqView = QQViewController()
         //qqView.title = ""
         Let skypeView = SkypeViewController()
         //skypeView.title = ""
         / / Declare two view controllers separately
         Let qq = UINavigationController(rootViewController:qqView)
         qq.tabBarItem.image = UIImage(named:"qq")
         qq.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
         Let skype = UINavigationController(rootViewController:skypeView)
         skype.tabBarItem.image = UIImage(named:"skype")
         skype.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
         self.viewControllers = [qq, skype]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.