Last active
June 11, 2018 17:09
-
-
Save bnickel/312e1d7d0e86e0a50a2b83ca10b32432 to your computer and use it in GitHub Desktop.
Randomly change the font size while running your app.
This file contains 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
@import UIKit; | |
@interface SEPrankster: NSObject | |
@property (class, readonly) SEPrankster *sharedPrankser; | |
- (void)setUpFontRandomness:(BOOL)run; | |
- (void)setFontCategory:(UIContentSizeCategory)category; | |
@end |
This file contains 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
@import JRSwizzle; | |
#import "SEPrankster.h" | |
static UIContentSizeCategory SEPranksterPrankContentSizeCategory = nil; | |
@interface SEPrankster () | |
@property (nonatomic) NSTimer *dynamicTypeTimer; | |
@end | |
@interface UIApplication (Prank) | |
- (UIContentSizeCategory)SE_preferredContentSizeCategory; | |
@end | |
@implementation SEPrankster | |
+ (void)load | |
{ | |
[UIApplication jr_swizzleMethod:@selector(preferredContentSizeCategory) withMethod:@selector(SE_preferredContentSizeCategory) error:NULL]; | |
} | |
+ (instancetype)sharedPrankster | |
{ | |
static SEPrankster *prankster; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
prankster = [[self alloc] init]; | |
}); | |
return prankster; | |
} | |
- (void)setUpFontRandomness:(BOOL)run | |
{ | |
if (run && self.dynamicTypeTimer == nil) { | |
self.dynamicTypeTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(changeSeats:) userInfo:nil repeats:YES]; | |
} else if (!run && self.dynamicTypeTimer) { | |
[self.dynamicTypeTimer invalidate]; | |
self.dynamicTypeTimer = nil; | |
[self setFontCategory:nil]; | |
} | |
} | |
- (void)changeSeats:(id)blahBlahBlah | |
{ | |
NSArray<UIContentSizeCategory> *fonts = @[UIContentSizeCategorySmall, UIContentSizeCategoryMedium, UIContentSizeCategoryLarge, UIContentSizeCategoryExtraSmall, UIContentSizeCategoryExtraLarge, UIContentSizeCategoryExtraExtraLarge, UIContentSizeCategoryExtraExtraExtraLarge]; | |
[self setFontCategory:fonts[arc4random_uniform((u_int32_t)fonts.count)]]; | |
} | |
- (void)setFontCategory:(UIContentSizeCategory)category | |
{ | |
SEPranksterPrankContentSizeCategory = category; | |
NSLog(@"Mix up time! Becoming: %@", [[UIApplication sharedApplication] preferredContentSizeCategory]); | |
[[NSNotificationCenter defaultCenter] postNotificationName:UIContentSizeCategoryDidChangeNotification object:[UIApplication sharedApplication] userInfo:@{UIContentSizeCategoryNewValueKey: [[UIApplication sharedApplication] preferredContentSizeCategory]}]; | |
} | |
@end | |
@implementation UIApplication (Prank) | |
- (UIContentSizeCategory)SE_preferredContentSizeCategory | |
{ | |
return SEPranksterPrankContentSizeCategory ?: [self SE_preferredContentSizeCategory]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment