티스토리 뷰


1. iOS 10 Widget 에서의 Height


iOS 8, 9 와는 다르게 10 에서는 위젯의 height 가 고정이 되어버렸다.

즉,


self.preferredContentSize = CGSizeMake(0, 200); 


와 같은 코드가 실제로 동작하지 않게되며 

위젯의 height 를 임의로 수정할 수 없게 되었다.


대신 Expand 모드를 만들어 NCWidgetProviding Delegate 에서 Content Size 를 수정할 수 있도록 열어놓았다.

사용법은 아래와 같다.


self.extensionContext.widgetLargestAvailableDisplayMode = NCWidgetDisplayModeExpanded; 


- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize {

    if (activeDisplayMode == NCWidgetDisplayModeExpanded) {

        self.preferredContentSize = CGSizeMake(0.0, 200.0);

    } else if (activeDisplayMode == NCWidgetDisplayModeCompact) {

        self.preferredContentSize = maxSize;

    }


참고)

http://stackoverflow.com/questions/38129047/what-is-the-height-of-the-new-ios-10-today-widget-extension




2. 유동글자 변경에 따른 Widget Max Height


"설정 > 디스플레이 및 밝기 > 텍스트 크기" 에서는 iPhone 에서 표시되는 글씨 크기를 수정할 수 있다.

이에 따라 위젯의 기본 Height 값이 달라지는데 그 결과는 아래와 같다.


UIContentSizeCategoryExtraSmall : 95

UIContentSizeCategorySmall : 100

UIContentSizeCategoryMedium : 105

UIContentSizeCategoryLarge ( default ) : 110

UIContentSizeCategoryExtraLarge : 120

UIContentSizeCategoryExtraExtraLarge : 130

UIContentSizeCategoryExtraExtraExtraLarge : 140


iOS 10 이상 버전에서는 Expand Mode 가 아닌 이상 

위젯 Height 를 임의로 수정할 수 없으므로

위젯 Max Height 의 최소 사이즈일 때의 95 를 기준으로 작업 후 View 들을 가운데 정렬하는 것이 좋아보인다.




3. Widget Max Height 를 알아내는 방법


NCWidgetProviding 에 Max Height 를 명시적으로 주는 framework Method 도 존재한다.


- (CGSize)widgetMaximumSizeForDisplayMode:(NCWidgetDisplayMode)displayMode NS_AVAILABLE_IOS(10_0) 


위 메소드는 NCWidgetDisplayMode 에 따른 CGSize 를 반환해준다.

만약, 내가 ExpandMode 로 preferredContentSize 를 지정해주었다면 해당 ContentSize 가 maxSize 값으로 나오게 된다.








공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함