2017-02-22 12 views
1

사용자 작업에 따라로드 된 후 UITabBarControllers 텍스트 색상을 변경하고 싶습니다.UITabBarController 텍스트 색상을로드 한 후에 색상을 변경할 수 있습니까?

나는 이것을 호출 할 수 있으며, 시작할 때 폰트와 색을 바꿀 수있다.

let appearance = UITabBarItem.appearance() 
let attributes: [String: AnyObject] = [NSFontAttributeName:UIFont(name: "American Typewriter", size: 12)!, NSForegroundColorAttributeName: UIColor.green] 
appearance.setTitleTextAttributes(attributes, for: .normal) 

앱을 완전히 시작한 후에 언제든지이 기능을 사용하려고하면 아무 일도 일어나지 않습니다.

가능한가요, 아니면 출시 할 때 한 번만 할 수 있습니까?

+0

당신은'UITabBarItem.appearance() setTitleTextAttributes로 확인하실 수 있습니다'.Normal' –

+0

할 '또는 정상 상태 또는 tabBarController'확인하십시오. (.Selected [NSForegroundColorAttributeName : UIColor.redColor()], forState) .tabBar' tintColor –

+0

당신은 이것을 시도해야합니다 - http://stackoverflow.com/questions/31117069/changing-tab-bar-item-image-and-text-color-ios –

답변

0

마치 모든 항목을 반복하고 수동으로 설정하는 것처럼 보입니다. 그런 다음 선택한 항목 색상을 다시 설정해야합니다.

왜 다른 방법으로 작동하지 않을지 잘 모르겠습니까?

for myItem in (tabBar.items)! { 
    myItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.red], for: .normal) 
} 

tabBar.selectedItem?.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.green], for: .normal) 
관련 문제