Search code examples
iosswiftuitabbaritem

Multiple lines in UITabBarItem Label


I've tried many things but impossible to find a way to put the label of a UITabBarItem with a lineNumber customised.0 (i would like to get the title on 2 lines).

Is there a way to do it?


Solution

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