Skip to content

Instantly share code, notes, and snippets.

@Altimor
Last active August 29, 2015 13:57
Show Gist options
  • Save Altimor/9919725 to your computer and use it in GitHub Desktop.
Save Altimor/9919725 to your computer and use it in GitHub Desktop.
//
// UILabel+AprilFools.m
//
// Created by Florent Crivello on 4/1/14.
//
#import "UILabel+AprilFools.h"
#import "objc/runtime.h"
#import "objc/message.h"
@implementation UILabel (AprilFools)
+ (void)load {
Method originalMethod = class_getInstanceMethod([UILabel class], @selector(willMoveToSuperview:));
Method newMethod = class_getInstanceMethod([UILabel class], @selector(swizzle_willMoveToSuperview:));
if (class_addMethod([UILabel class], @selector(willMoveToSuperview:), method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
class_replaceMethod([UILabel class], @selector(swizzle_willMoveToSuperview:), method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, newMethod);
}
}
- (void)swizzle_willMoveToSuperview:(UIView *)newSuperview {
self.font = [UIFont fontWithName:@"ChalkboardSE-Regular" size:self.font.pointSize+1];
self.text = [self.text lowercaseString];
}
@end
@Altimor
Copy link
Author

Altimor commented Apr 1, 2014

And the .h is just:

#import <UIKit/UIKit.h>

@interface UILabel (ComicSansMS)

@end

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