Created
July 30, 2014 04:42
-
-
Save ierceg/38e524986251ec161472 to your computer and use it in GitHub Desktop.
UIView category which spreads antialiasing to layers
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
// Originally found at http://pastebin.com/kdUHWMZf | |
// Fixed the recursion not working on layers of subviews. | |
@interface UIView (LayerEdgeAntialiasing) | |
/** Uses the -setAllowsEdgeAntialiasing: method from CALayer prior to iOS 7, and also can applies it to every sublayers (and sublayers's of sublayers', and so on) if you want to. */ | |
@property (nonatomic, assign) BOOL allowsLayerEdgeAntialiasing; | |
- (void)setAllowsLayerEdgeAntialiasing:(BOOL)allowsLayerEdgeAntialiasing applyToSublayers:(BOOL)applyToSublayers; | |
@end | |
@implementation UIView (LayerEdgeAntialiasing) | |
- (BOOL)allowsLayerEdgeAntialiasing { | |
if([CALayer instancesRespondToSelector:@selector(setAllowsEdgeAntialiasing:)]) { | |
return [[self layer] allowsEdgeAntialiasing]; | |
} | |
return NO; | |
} | |
- (void)setAllowsLayerEdgeAntialiasing:(BOOL)allowsLayerEdgeAntialiasing { | |
[self setAllowsLayerEdgeAntialiasing:allowsLayerEdgeAntialiasing applyToSublayers:NO]; | |
} | |
- (void)setAllowsLayerEdgeAntialiasing:(BOOL)allowsLayerEdgeAntialiasing applyToSublayers:(BOOL)applyToSublayers | |
{ | |
if([CALayer instancesRespondToSelector:@selector(setAllowsEdgeAntialiasing:)]) | |
{ | |
if ([[self layer] allowsEdgeAntialiasing] != allowsLayerEdgeAntialiasing) { | |
[[self layer] setAllowsEdgeAntialiasing:allowsLayerEdgeAntialiasing]; | |
if (applyToSublayers) { | |
[[self subviews] enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) { | |
[subview setAllowsLayerEdgeAntialiasing:allowsLayerEdgeAntialiasing applyToSublayers:applyToSublayers]; | |
}]; | |
} | |
} | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment