ios - How to make simple UITabBarController in Swift? -
i created uitabbarcontroller class
i created 2 view controllers , set title property each one
i want change size , color of text label within tabs
i set tab color , frame using
uitabbar.appearance().bartintcolor = uicolor.bluecolor() tabbar.frame = cgrectmake(0, 0, view.frame.width, 100)
now adjusting tabs, tried each of following
uitabbaritem.appearance().settitletextattributes(nsdictionary(object: uicolor.whitecolor(), forkey: nsforegroundcolorattributename), forstate: uicontrolstate.normal)
that changed text color white
uitabbaritem.appearance().settitletextattributes(nsdictionary(object: uicolor.whitecolor(), forkey: nsforegroundcolorattributename), forstate: uicontrolstate.normal) uitabbaritem.appearance().settitletextattributes(nsdictionary(object: uifont(name: "helvetica", size: 16.0)!, forkey: nsfontattributename), forstate: uicontrolstate.normal)
that changed size of text, not color !
uitabbaritem.appearance().settitletextattributes(nsdictionary(objects: [nsforegroundcolorattributename, nsfontattributename], forkeys: [uicolor.whitecolor(), uifont(name: "helvetica", size: 16.0)!]), forstate: uicontrolstate.normal) // or var attributes = nsdictionary(objects: [nsforegroundcolorattributename, nsfontattributename], forkeys: [uicolor.whitecolor(), uifont(name: "helvetica", size: 16.0)!]) uitabbaritem.appearance().settitletextattributes(attributes, forstate: uicontrolstate.normal)
that last bit did nothing @ all, neither setting color nor size of tabs text
update------
to more precise, above code tried within uitabbarcontroller child class in viewwillappear
furthermore, curious how make whole tabs (tab-able) , not text label part of it, , add sort of line separator between tabs
i found out how make happen
setting title color , size has go through uitabbaritem appearance "proxy"
override func viewwilllayoutsubviews() { self.tabbar.frame = cgrectmake(0, 20, view.frame.width, 50) var font = uifont(name: "helvetica", size: 16) var objs = nsarray(objects: font!, uicolor.whitecolor()) var keys = nsarray(objects: nsfontattributename, nsforegroundcolorattributename) uitabbaritem.appearance().settitletextattributes(nsdictionary(objects: objs, forkeys: keys), forstate: uicontrolstate.normal) }
Comments
Post a Comment