본문 바로가기

iOS

[iOS] Accessibility Inspector를 통해 경고 없애기!

xcode => Open Developer Tool => Accessibility Inspector
이래 접근해서 실행시킬 수 있다.

 

먼저 좌측상단에 시뮬레이터로 설정을 해줘야함 !

우측상단에 Inspector영역이 존재하는데
순서대로 Inspection 영역 / Audit 영역 / Settings 영역이있는데
중간의 Audit인 감사하는 영역을 확인하면 됨

그러면 구현한 앱들에 경고들이 하나둘씩 보일텐데 이를 해결해주면 된다.
경고메세지 우측에 눈표시와 느낌표를 확인하면 힌트를 얻을 수 있다.



  1. Button 속 TitleLable의 폰트 사이즈가 Dynamic type에 적용되지 않았다.
  2. Label 속 image Font의 사이즈가 Dynamic type에 적용되지 않았다.
  3. 재고 표시 Label의 Font의 사이즈가 Dynamic type에 적용되지 않았다.

# 접근성 권한 부여 해결법

// adjustsFontForContentSizeCategory
    // 콘텐츠의 크기가 변경될떄 개체가 글꼴을 자동으로 업데이트하는지 여부를 결정하는 프로퍼티
    
    // AdjustsFontSizeToFitWidth
    // 너비에 맞게 글꼴 크기를 줄이는지 여부를 결정하는 프로퍼티

    private func configureDynamicTypeTofruitImageLabels() {
        for index in fruitImageLabels.indices {
            fruitImageLabels[index].font = UIFont.preferredFont(forTextStyle: .largeTitle)
            fruitImageLabels[index].adjustsFontForContentSizeCategory = true
        }
    }
    
    private func configureDynamicTypeTobuttons() {
        for index in juiceButtons.indices {
            juiceButtons[index].titleLabel?.adjustsFontForContentSizeCategory = true
        }
    }
    
    private func configureDynamicTypeToLabels() {
        for index in fruitStockLabels.indices {
            fruitStockLabels[index].adjustsFontForContentSizeCategory = true
        }
    }
 

- adjustsFontForContentSizeCategory

  • 콘텐츠의 크기가 변경될떄 개체가 글꼴을 자동으로 업데이트하는지 여부를 결정하는 프로퍼티
  • 유효한 텍스트 스타일이 있는 또는 메서드를 사용하여 적용해야 합니다
    - preferredFont(forTextStyle:) / preferredFont(forTextStyle:compatibleWith:)
  • 스케일링 방법 중 하나를 사용하여 적용해야 합니다 .UIFontMetrics

- AdjustsFontSizeToFitWidth

  • 텍스트가 text레이블의 경계 사각형을 초과하는 경우 레이블은 텍스트가 맞거나 최소 글꼴 크기로 글꼴이 축소될 때까지 글꼴 크기를 줄입니다.
  • 이 속성의 기본값은 false입니다.
  • true을 수정하여 적절한 최소 글꼴 크기도 설정해야 합니다 .
  • 이 자동 축소 동작은 한 줄 레이블에만 사용하기 위한 것입니다


# Accessibility Properties 사용하기 

    private func configureDynamicTypeToLabels() {
        for index in fruitStockLabels.indices {
            fruitStockLabels[index].adjustsFontForContentSizeCategory = true
            fruitStockLabels[index].accessibilityLabel = "쥬스한잔?"
            fruitStockLabels[index].accessibilityValue = "10개"
            fruitStockLabels[index].accessibilityTraits = .header
            fruitStockLabels[index].accessibilityHint = "딸기당근수박참외메론"
        }
    }

 

- accessibilityLabel

요소에 대한 이름을 넣는 프로퍼티이다. 정적인값
ex) “딸기쥬스”

- accessibilityHint

요소에 대한 작업을 수행한 결과에 대한 간략한 설명을 넣는 프로퍼티이다.
ex) “쥬스 재고를 알려줍니다.”

- accessibilityValue

요소에 대한 값을 넣는 프로퍼티이다. 동적인값
ex)10개

- accessibilityTraits

요소에 대한 특성을 입력하는 라인
ex)

Ispection영역에서 네비게이션을 재생하면 앱의 모든 UI화면구성에 관련된 accessibility Property들이 하나둘 Voice음성이 나오는데 순서대로 들어볼 수 있다.

순서는 label -> Value -> Traits -> Hint 프로퍼티 순서이다.

 

여기서 나오는 경고들은 권장사항이지 필수사항은아니다. 고로 필요에 의해서 사용하면된다.

# Accessibility Property 사용할시! 주의할점! (WWDC)

- VoiceOver가 "버튼, 버튼, 버튼 "을 말하지 않도록 레이블을 추가하는 것을 잊지 마세요 (중복제거)

- 요소의 타입을 label에 포함시키지마세요 보이스오버는 이미 포함시키고 있습니다.

UI 가 변경 되면 레이블을 업데이트합니다 . 따라서 삭제 버튼으로 변경 되는 추가 버튼이 있는 경우

 

- VoiceOver가 버튼의 올바른 상태를 읽도록 레이블 을 업데이트해야 합니다.

 

- 재생 노래, 다음 노래, 이전 노래 와 같은 중복을 피하십시오 . 음악 플레이어에서 내가 카트 에 땅콩 버터, 바나나 또는 멋진 쿠키를 추가하는지 알 수 있도록 충분한 컨텍스트를 제공하는 것을 잊지 마십시오.

 

- 휴지통에서 현재 항목을 삭제하고 이동하는 것과 같은 장황한 레이블을 피하십시오 . 그 멋진 쿠키 몬스터 스티커 와 같은 큰 이유가 없다면 .



Reference

 

Writing Great Accessibility Labels - WWDC19 - Videos - Apple Developer

Great accessibility labels are the difference between someone using and loving your app or someone deleting your app. Experience...

developer.apple.com

- https://developer.apple.com/documentation/objectivec/nsobject/1615202-accessibilitytraits#:~:text=list%20of%20traits.-,See%20Also,Constants%20that%20describe%20how%20an%20accessibility%20element%20behaves.,-%EF%A3%BF