Bläddra i källkod

Use monospace digits for time label. Fixes #351.

Zev Eisenberg 6 år sedan
förälder
incheckning
b7d927212a
1 ändrade filer med 19 tillägg och 0 borttagningar
  1. 19 0
      Sources/VLCTimeNavigationTitleView.m

+ 19 - 0
Sources/VLCTimeNavigationTitleView.m

@@ -13,6 +13,7 @@
 
 
 #import "VLCTimeNavigationTitleView.h"
+@import CoreText.SFNTLayoutTypes;
 
 @implementation VLCTimeNavigationTitleView
 
@@ -21,7 +22,25 @@
     self.minimizePlaybackButton.accessibilityLabel = NSLocalizedString(@"MINIMIZE_PLAYBACK_VIEW", nil);
     self.aspectRatioButton.accessibilityLabel = NSLocalizedString(@"VIDEO_ASPECT_RATIO_BUTTON", nil);
     [self.aspectRatioButton setImage:[UIImage imageNamed:@"ratioIcon"] forState:UIControlStateNormal];
+    [self setupTimeDisplayFont];
 
     [super awakeFromNib];
 }
+
+/**
+ Use a monospace variant for the digits so the label's width does not jitter as the numbers change.
+ */
+- (void)setupTimeDisplayFont
+{
+    UIFontDescriptor *descriptor = self.timeDisplayButton.titleLabel.font.fontDescriptor;
+    NSDictionary *featureSettings = @{
+                                      UIFontFeatureTypeIdentifierKey: @(kNumberSpacingType),
+                                      UIFontFeatureSelectorIdentifierKey: @(kMonospacedNumbersSelector)
+                                      };
+    NSDictionary *attributes = @{ UIFontDescriptorFeatureSettingsAttribute: @[featureSettings] };
+    UIFontDescriptor *newDescriptor = [descriptor fontDescriptorByAddingAttributes: attributes];
+    UIFont *newFont = [UIFont fontWithDescriptor:newDescriptor size:0];
+    self.timeDisplayButton.titleLabel.font = newFont;
+}
+
 @end