2017-05-03 3 views
0

선택한 UITabBarItem의 글꼴을 굵은 글꼴로 변경하고 싶습니다. 나는 이미지와 텍스트를 흰색으로 설정하고 글꼴을 설정하기 위해 다음을 수행했지만 글꼴이 아닌 UITabBarItem을 선택할 때만 색상이 변경됩니다.선택한 UITabBarItem의 글꼴을 대칭 코드로 변경

// Normal font  
[self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MY_LIGHT_FONT, NSFontAttributeName, [UIColor grayColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal]; 

// Selected font 
[self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MY_BOLD_FONT, NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName,nil] forState:UIControlStateSelected]; 

선택한 글꼴로 아무 것도 바뀌지 않습니다.

enter image description here

달력 텍스트는 굵은해야한다.

+0

확인이 ans와 http://stackoverflow.com/a/41082581/4831524 –

+0

이 HTTP를 찾습니다//library/questions/11069437/changing-font-in-uitabbaritem – liangju

+0

@liangju UIStateNormal의 경우 이미 내 솔루션이 작동하지만 선택되지 않았습니다. –

답변

0

이 시도 :

// Normal font  
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MY_LIGHT_FONT, NSFontAttributeName, [UIColor grayColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal]; 

// Selected font 
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MY_BOLD_FONT, NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName,nil] forState:UIControlStateSelected]; 
+0

슬프게도 이것은 선택한 색상에만 영향을 미칩니다 .. –

0

노력이 :

// Normal font 
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"your-font" size:10.f], NSFontAttributeName, nil] forState:UIControlStateNormal]; 

    //selected state 
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"your-font bold" size:10.f], NSFontAttributeName, nil] forState:UIControlStateSelected]; 
+0

그건 내 솔루션과 같습니다. –

2
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:MONSREGULAR size:10.0f], 
                 NSForegroundColorAttributeName :[UIColor colorWithRed:0.004 green:0.820 blue:0.369 alpha:1.00]; 
                 } forState:UIControlStateSelected]; 


    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:MONSREGULAR size:10.0f], 
                 NSForegroundColorAttributeName :[UIColor darkgraycolor]; 
                 } forState:UIControlStateNormal]; 
+0

iOS11에서 선택한 상태에 대해 글꼴 매개 변수가 작동하지 않습니다. –

관련 문제