Last active
January 2, 2016 05:19
-
-
Save steipete/8255790 to your computer and use it in GitHub Desktop.
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
static void PSPDFFixCenteringInPrinterBrowserViewController(void) { | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
// Patch the `UIPrinterSearchingView` class so we get a sane label placement in iOS 7. | |
Class printerSearchingViewClass = NSClassFromString([NSString stringWithFormat:@"UI%@Searching%@", @"Printer", @"View"]); | |
if (printerSearchingViewClass) { | |
SEL customLayoutSubviewsSEL = NSSelectorFromString(@"pspdf_layoutSubviews"); | |
id customLayoutSubviews = ^(UIView *_self) { | |
((void( *)(id, SEL))objc_msgSend)(_self, customLayoutSubviewsSEL); // call original. | |
@try { | |
if (PSPDFIsUIKitFlatMode()) { | |
UIView *searchingLabel = PSPDFViewInsideViewWithPrefix(_self, NSStringFromClass(UILabel.class)); | |
UIView *searchingIndicator = PSPDFViewInsideViewWithPrefix(_self, NSStringFromClass(UIActivityIndicatorView.class)); | |
if (searchingLabel && searchingIndicator) { | |
CGRect centeredRect = PSPDFAlignRectangles(searchingLabel.frame, _self.bounds, PSPDFRectAlignCenter); | |
CGRect searchingLabelRect = searchingLabel.frame; | |
searchingLabelRect.origin.y = centeredRect.origin.y; | |
searchingLabel.frame = searchingLabelRect; | |
CGRect indicatorFrame = searchingIndicator.frame; | |
indicatorFrame.origin.y = searchingLabel.frame.origin.y; | |
searchingIndicator.frame = indicatorFrame; | |
} | |
} | |
} | |
@catch (NSException *exception) {} // noncritical layout issue | |
}; | |
PSPDFReplaceMethodWithBlock(printerSearchingViewClass, @selector(layoutSubviews), customLayoutSubviewsSEL, customLayoutSubviews); | |
} | |
}); | |
} |
Peter, I've got a question about where they get initialized. Do you just set up fixes like this in the +load
method for some part of your library? Otherwise, where do you recommend?
I would use attribute(constructor)
Is [NSString stringWithFormat:@"UI%@Searching%@", @"Printer", @"View"]
to prevent having UIPrinterSearchingView
string in the binary and hence possible app store problems?
(awesome article by the way)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tired of waiting for Apple to fix UI bugs?
http://petersteinberger.com/blog/2014/fixing-what-apple-doesnt/
Before: https://twitter.com/steipete/status/419462996617097216
After: https://twitter.com/steipete/status/419469468562366464
Code ships with PSPDFKit: http://pspdfkit.com/