Created
March 7, 2012 17:55
-
-
Save florianbachmann/1994696 to your computer and use it in GitHub Desktop.
How to write a pixel perfect backbutton in code. (stuff goes into viewDidLoad). Taken from http://pspdfkit.com
This file contains 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
forwardBarButtonItem_ = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(goForward:)]; | |
// back button needs more treatment... | |
UIGraphicsBeginImageContextWithOptions(CGSizeMake(27, 22), NO, 0.0); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSetFillColor(context, CGColorGetComponents([UIColor blackColor].CGColor)); | |
CGContextBeginPath(context); | |
CGContextMoveToPoint(context, 8.0f, 13.0f); | |
CGContextAddLineToPoint(context, 24.0f, 4.0f); | |
CGContextAddLineToPoint(context, 24.0f, 22.0f); | |
CGContextClosePath(context); | |
CGContextFillPath(context); | |
UIImage *backImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
PSPDF_IF_IOS5_OR_GREATER( | |
UIGraphicsBeginImageContextWithOptions(CGSizeMake(20, 20), NO, 0.0); | |
context = UIGraphicsGetCurrentContext(); | |
CGContextSetFillColor(context, CGColorGetComponents([UIColor blackColor].CGColor)); | |
CGContextBeginPath(context); | |
CGContextMoveToPoint(context, 8.0f, 13.0f); | |
CGContextAddLineToPoint(context, 20.0f, 6.0f); | |
CGContextAddLineToPoint(context, 20.0f, 20.0f); | |
CGContextClosePath(context); | |
CGContextFillPath(context); | |
UIImage *smallBackImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
backBarButtonItem_ = [[UIBarButtonItem alloc] initWithImage:backImage landscapeImagePhone:smallBackImage style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)]; | |
) | |
PSPDF_IF_PRE_IOS5(backBarButtonItem_ = [[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)];) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment