Last active
June 19, 2021 17:09
-
-
Save Esquilli/0e6bb50a3d3bf30c8988291430221fef to your computer and use it in GitHub Desktop.
How to use iOS13 font picker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This worked for me. thank you very much!