Skip to content

Instantly share code, notes, and snippets.

@Esquilli
Last active June 19, 2021 17:09
Show Gist options
  • Save Esquilli/0e6bb50a3d3bf30c8988291430221fef to your computer and use it in GitHub Desktop.
Save Esquilli/0e6bb50a3d3bf30c8988291430221fef to your computer and use it in GitHub Desktop.
How to use iOS13 font picker
// Add this to your preferences class
-(void)pickFont {
UIFontPickerViewControllerConfiguration *config = [[UIFontPickerViewControllerConfiguration alloc] init];
config.includeFaces = YES;
config.displayUsingSystemFont = NO;
UIFontPickerViewController *fontPicker = [[UIFontPickerViewController alloc] initWithConfiguration:config];
fontPicker.delegate = self;
[self presentViewController:fontPicker animated:YES completion:nil];
}
-(void)fontPickerViewControllerDidPickFont:(UIFontPickerViewController *)fontPicker {
UIFontDescriptor *descriptor = fontPicker.selectedFontDescriptor;
NSError *error = nil;
NSData *encodedDescriptor = [NSKeyedArchiver archivedDataWithRootObject:descriptor requiringSecureCoding:NO error:&error];
HBPreferences *pfs = [[HBPreferences alloc] initWithIdentifier:@"com.esquilli.viper"];
[pfs setObject:encodedDescriptor forKey:@"CustomFont"];
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)kReloadPrefs, nil, nil, true);
[fontPicker dismissViewControllerAnimated:YES completion:nil];
}
// Delegate
@interface Class : Anotheclass<UIFontPickerViewControllerDelegate>
...
@end
@0xkuj
Copy link

0xkuj commented Aug 28, 2020

This worked for me. thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment