Skip to content

Instantly share code, notes, and snippets.

@steipete
Last active January 2, 2016 05:19
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steipete/8255790 to your computer and use it in GitHub Desktop.
Save steipete/8255790 to your computer and use it in GitHub Desktop.
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);
}
});
}
@Daniel1of1
Copy link

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