Swift tab bar button for iOS development Uitabbaritem style modification (icon text size, color, etc.)

Source: Internet
Author: User

Uitabbaritem in the development of a very common use it can be used to set the font color and picture settings, and so on, let's take a look at the iOS development of the Swift tab bar button Uitabbaritem style modification (icon text size, color, etc.) example, the details are as follows.

Recommended dimensions and maximum supported dimensions for 1,tabbaritem pictures

The following are the dimensions of the tab bar (Uitabbar) that do not compress deform at 1x, 2x, 3x, respectively:

@1x: Recommended x 25 (max: 32 x)
@2x: Recommended x 50 (max: 64 x)
@3x: Recommended x 75 (max: 144 x 96)

Below is the 2x, the left of the use of a picture of x 50, the right to use a picture of x 64, you can compare the following:

Import UIKit

Class Maintabviewcontroller:uitabbarcontroller
{
Override Func Viewdidload ()
{
Super.viewdidload ()
Total of two views included
Let Qqview = View1viewcontroller ()
Qqview.title = "QQ"
Let Androidview = View1viewcontroller ()
Androidview.title = "Skype"

Declaration of two view controllers separately
Let QQ = Uinavigationcontroller (Rootviewcontroller:qqview)
Qq.tabBarItem.image = UIImage (named: "QQ")
Let Android = Uinavigationcontroller (Rootviewcontroller:androidview)
Android.tabBarItem.image = UIImage (named: "Skype")
Self.viewcontrollers = [Qq,android]

QQ View is selected by default
Self.selectedindex = 0
}
}

2. Modify the color of the picture and text

The picture and text of the default unchecked label are gray, Blue is selected, and the following changes to Orange:
(1) Change of picture and text at the same time

Picture text color together
Self.tabBar.tintColor = Uicolor.orangecolor ()

(2) Change text color only

Change text color
Uitabbaritem.appearance (). Settitletextattributes (
[NSForegroundColorAttributeName:UIColor.grayColor ()], forstate:. Normal)
Uitabbaritem.appearance (). Settitletextattributes (
[NSForegroundColorAttributeName:UIColor.orangeColor ()], forstate:. Selected)

(3) Change the color of the image only

Self.tabBar.tintColor = Uicolor.orangecolor ()
Text color Restore
Uitabbaritem.appearance (). Settitletextattributes (
[NSForegroundColorAttributeName:self.view.tintColor], forstate:. Selected)

3, use a different picture when selected, not selected
The default label is selected, not selected, and uses the same picture, except for different colors. We can also use two different images to represent the two states.


Qq.tabbaritem = Uitabbaritem (title: "QQ", Image:uiimage (named: "QQ"),
Selectedimage:uiimage (named: "Qq_active"))

Android.tabbaritem = Uitabbaritem (title: "Android", Image:uiimage (named: "Android"),
Selectedimage:uiimage (named: "Android_active"))

4, use the original color of the picture

By default, the renderer will render a single color regardless of the original color, although it fits the trend of flattening now, but sometimes we want to use the original image.
The following example uses a non-shaded original picture when the label is selected (the original image is still rendered dimmed and, of course, can be used)

Qq.tabbaritem = Uitabbaritem (title: "QQ", Image:uiimage (named: "Qq_color"),
Selectedimage:uiimage (named: "Qq_color")? Imagewithrenderingmode (. alwaysoriginal))

Android.tabbaritem = Uitabbaritem (title: "Android", Image:uiimage (named: "Android_color"),
Selectedimage:uiimage (named: "Android_color")? Imagewithrenderingmode (. alwaysoriginal))

The Swift tab bar button for iOS development Uitabbaritem style modification (icon text size, color, etc.)

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.