Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 316f1ee

Browse files
committed
Merged PR 414899: MSLabel and MSButton should respect "adjustFontForContentSizeCategory" property
Currently, both MSLabel and MSButton listen to content size category change notification, and update its font size accordingly. We should follow the iOS native behavior that only when "adjustFontForContentSizeCategory" is true, we should update dynamically update the font size. iOS default for adjustFontForContentSizeCategory is set to false, but for MSLabel and MSButton we will set it to true.. Button, label, cell demo in various accessibility text sizes
1 parent dc31dda commit 316f1ee

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

OfficeUIFabric.Demo/OfficeUIFabric.Demo/Demos/ObjectiveCDemoController.m

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ - (void)viewDidLoad {
3636
[[self.container leftAnchor] constraintEqualToAnchor:[self.scrollingContainer leftAnchor]],
3737
[[self.container widthAnchor] constraintEqualToAnchor:[self.scrollingContainer widthAnchor]],
3838
]];
39+
40+
MSButton *testButton = [self createButtonWithTitle:@"Test" action:nil];
41+
[self.container addArrangedSubview:testButton];
3942
}
4043

4144
- (UIStackView *)createVerticalContainer {

OfficeUIFabric/Controls/MSButton.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import UIKit
4848

4949
// MARK: - MSButton
5050

51+
/// By default, `titleLabel`'s `adjustsFontForContentSizeCategory` is set to true to automatically update its font when device's content size category changes
5152
@IBDesignable
5253
open class MSButton: UIButton {
5354
private struct Constants {
@@ -119,9 +120,8 @@ open class MSButton: UIButton {
119120
}
120121

121122
titleLabel?.font = Constants.titleFont
123+
titleLabel?.adjustsFontForContentSizeCategory = true
122124
update()
123-
124-
NotificationCenter.default.addObserver(self, selector: #selector(handleContentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
125125
}
126126

127127
open override func layoutSubviews() {
@@ -159,8 +159,4 @@ open class MSButton: UIButton {
159159

160160
contentEdgeInsets = style.contentEdgeInsets
161161
}
162-
163-
@objc private func handleContentSizeCategoryDidChange() {
164-
update()
165-
}
166162
}

OfficeUIFabric/Controls/MSLabel.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import UIKit
77

8+
/// By default, `adjustsFontForContentSizeCategory` is set to true to automatically update its font when device's content size category changes
89
open class MSLabel: UILabel {
910
@objc open var colorStyle: MSTextColorStyle = .regular {
1011
didSet {
@@ -55,6 +56,7 @@ open class MSLabel: UILabel {
5556

5657
updateFont()
5758
updateTextColor()
59+
adjustsFontForContentSizeCategory = true
5860

5961
NotificationCenter.default.addObserver(self, selector: #selector(handleContentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
6062
if #available(iOS 13, *) { } else {
@@ -76,7 +78,9 @@ open class MSLabel: UILabel {
7678
}
7779

7880
@objc private func handleContentSizeCategoryDidChange() {
79-
updateFont()
81+
if adjustsFontForContentSizeCategory {
82+
updateFont()
83+
}
8084
}
8185

8286
@objc private func handleDarkerSystemColorsStatusDidChange() {

0 commit comments

Comments
 (0)