Created
December 5, 2011 15:16
-
-
Save tmdvs/1433922 to your computer and use it in GitHub Desktop.
Subtracting a string from inside a CALayer. Like an cut out mask in Photoshop.
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
CALayer *myLayer = [CALayer layer]; | |
[myLayer setFrame:rect]; | |
[myLayer setBackgroundColor:[myColour CGColor]]; | |
[myLayer setCornerRadius:radius]; | |
UIGraphicsBeginImageContext([myLayer frame].size); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSaveGState(context); | |
[myLayer renderInContext:context]; | |
CGContextRestoreGState(context); | |
CGContextSetBlendMode(context, kCGBlendModeClear); | |
[myString drawInRect:myStringsBounds withFont:[UIFont boldSystemFontOfSize: 11]]; | |
CGContextSetBlendMode(context, kCGBlendModeNormal); | |
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
[outputImage drawInRect:rect]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wow niice!
can you draw an image instead at line 17 and it subtracts it from the layer??