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); | |
} | |
}); | |
} |
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
I would use attribute(constructor)