Multiple Lines in UItabbaritem Label

Multiple lines in UITabBarItem Label

Now it contains two subviews. At 0 it is imageView and at 1 it is label.
Now make the height of imageview a bit smaller so that you can give the height of label a bit larger to have multiple lines. Set the property ofnumberoflines of the label to 0 via code.

let viewTabBar = tabBarItem.value(forKey: "view") as? UIView
let imageView = viewTabBar?.subviews[0] as? UIImageView
let label = viewTabBar?.subviews[1] as? UILabel

and now play with this label.

Custom UITabBarItem without title label

made same task just today.

Since I can't use full space of tab bar for item image I just change tab bar background when user press any tab.

  1. So the first step is to prepare background images with full size buttons for every tab selected.

  2. Then create custom class and assign it for your tab bar controller

  3. In your custom class set background image for first tab in ViewDidLoad:

    [[self tabBar] setBackgroundImage:[UIImage imageNamed:@"tabShopsActive"]];
    [[self tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"tabSelection"]];
  4. Add background change for every UIController in ViewWillAppear:

    UITabBarController *bar = [self tabBarController];
    [bar.tabBar setBackgroundImage:[UIImage imageNamed:@"tabDiscountsActive"]];

So now when user press any tab Tab Bar change background to show correct picture for it.

It is my resulting tab bar when second tab selected:

Tab bar without labels



Related Topics



Leave a reply



Submit