修改UITabBarItem字型顏色

im5437發表於2015-05-29
  • 修改UITabBarItem下面字型的顏色,如圖:

    \

    [[UITabBarItemappearance]setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor],UITextAttributeTextColor,nil]forState:UIControlStateNormal];

    [[UITabBarItemappearance]setTitleTextAttributes: [NSDictionarydictionaryWithObjectsAndKeys:[UIColorredColor],UITextAttributeTextColor,nil]forState:UIControlStateSelected];

    這個時候會報警告'UITextAttributeTextColor' is deprecated in iOS 7. The iOS 7 key is 'NSForegroundColorAttributeName

    然後替換一下就可以了,不過NSForegroundColorAttributeName最底支援到ios6.0

    [[UITabBarItemappearance]setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor],NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];

    [[UITabBarItemappearance]setTitleTextAttributes: [NSDictionarydictionaryWithObjectsAndKeys:[UIColorredColor],NSForegroundColorAttributeName,nil]forState:UIControlStateSelected];

    以上是改變字型顏色的,圖片顏色無法改變,

    [[UITabBarappearance]setTintColor:[UIColorredColor]];

    但是上面這一句就可以改變並設定點選後的圖片和文字顏色了。

相關文章