Skip to content

Instantly share code, notes, and snippets.

@steipete steipete/UIKitPatches.m
Last active Jan 2, 2016

Embed
What would you like to do?
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);
}
});
}
@steipete

This comment has been minimized.

@streeter

This comment has been minimized.

Copy link

commented Jan 25, 2014

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?

@steipete

This comment has been minimized.

Copy link
Owner Author

commented Jan 25, 2014

I would use attribute(constructor)

@Daniel1of1

This comment has been minimized.

Copy link

commented Feb 12, 2014

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
You can’t perform that action at this time.