Appearance Proxy를 사용해서 UITabBar Item의 selectedImage속성 적용이 안됩니다

1 답변 글타래를 보이고 있습니다
  • 글쓴이
    • mi kim
      참가자
      • 글작성 : 10
      • 답글작성 : 8

      탭바UI에서 탭바들이 선택되었을 때의 탭바 아이템 이미지를 설정하는 부분입니다.

      // 탭 바 아이템 전체를 순회하면서 selectedImage 속성에 이미지를 설정

      if let tbItems = tabbarController.tabBar.items {
      for tbItem in tbItems {
                 let image = UIImage(named: “이미지”)?.withRenderingMode(.alwaysOriginal)
                tbItem.selectedImage = image
               }
      }

       

      잘 작동하던 위의 코드를 Appearance Proxy를 이용해서 다음과 같이 수정했습니다.
      let img = UIImage(named: “이미지”)?.withRenderingMode(.alwaysOriginal)
      UITabBarItem.appearance().selectedImage = img

       

      예상과 달리 에뮬레이터에서 화면이 제대로 뜨지 않고 작동하지 않습니다..

      selectedImage 속성은 프록시 객체로 설정할 수 없는건가요??

       

      • 이 게시글은 mi kim에 의해 3 years, 4 months 전에 수정됐습니다.
    • 야곰
      키 마스터
      • 글작성 : 37
      • 답글작성 : 580

      https://developer.apple.com/documentation/uikit/uiappearance

      여기에 보면 appearance 대신에 다른 계층에 속해있는 아이템에 apperance를 적용할 수 있는 다른 메서드도 있는것 같아요. 이거를 시도해보면 어떨까요?

      또, appearance 정의부 가니 이런 코멘트도 남아있네요.

       

      스크린샷 2020-12-23 오전 10.34.12

      • mi kim
        참가자
        • 글작성 : 10
        • 답글작성 : 8

        [[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[UISplitViewController class]]]

                         setBarTintColor:myColor];

         

        계속 보고 있는 중인데 이런 형식의 문법은 처음보아서 잘 이해가 가지 않네요 ㅠㅠ…

        • 야곰
          키 마스터
          • 글작성 : 37
          • 답글작성 : 580

          ㅎㅎ Objective-C 코드입니다.
          스위프트로 따지자면
          UINavigationBar.appearance(whenContainedInInstancesOf: UISplitViewController.self).barTintColor = myColor

          요정도 될겁니다

          • 이 답변은 야곰에 의해 3 years, 4 months 전에 수정됐습니다.
1 답변 글타래를 보이고 있습니다
  • 답변은 로그인 후 가능합니다.

logo landscape small

사업자번호 : 743-81-02195
통신판매업 신고번호 : 제 2022-충북청주-1278 호
고객센터 : 카카오톡채널 @yagom