Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 1 file changed
  • 0 commit comments
  • 4 contributors
Showing with 48 additions and 16 deletions.
  1. +48 −16 Classes/ButtonMakerViewController.m
View
64 Classes/ButtonMakerViewController.m
@@ -110,30 +110,62 @@ -(IBAction) sizeSlideChanged:(id)sender {
heightLabel.text = [NSString stringWithFormat:@"%.0f", roundf(heightSlider.value)];
[self updateButton];
}
--(IBAction) saveTapped:(id)sender {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
+
+- (void) saveImageToFile: (NSString *) filePath isRetina:(BOOL)isRetina
+{
+ if (isRetina)
+ {
+ if (UIGraphicsBeginImageContextWithOptions == NULL)
+ {
+ return;
+ }
+ UIGraphicsBeginImageContextWithOptions(theButton.frame.size, NO, 2.0);
+ }
+ else
+ {
+ UIGraphicsBeginImageContext(theButton.frame.size);
+ }
- // the path to write file
- NSString *buttonFile = [documentsDirectory stringByAppendingPathComponent:@"button.png"];
- NSString *buttonHighlightFile = [documentsDirectory stringByAppendingPathComponent:@"button-highlight.png"];
- UIGraphicsBeginImageContext(theButton.frame.size);
CGContextRef theContext = UIGraphicsGetCurrentContext();
[theButton.layer renderInContext:theContext];
+ CGRect overDrawRects[] = {CGRectMake(10, 0, 1, theButton.frame.size.height), CGRectMake(theButton.frame.size.width - 11, 0, 1, theButton.frame.size.height)};
+
+ [[UIColor clearColor] set];
+
+ for (int i = 0; i < 2; i++) {
+ UIRectFill(overDrawRects[i]);
+ CGContextSaveGState(theContext);
+ CGContextClipToRect(theContext, overDrawRects[i]);
+ CGContextTranslateCTM(theContext, -1, 0);
+ [theButton.layer renderInContext:theContext];
+ CGContextRestoreGState(theContext);
+ }
+
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
NSData *theData = UIImagePNGRepresentation(theImage);
- [theData writeToFile:buttonFile atomically:NO];
- UIGraphicsEndImageContext();
+ [theData writeToFile: filePath atomically:NO];
+ UIGraphicsEndImageContext();
+}
+
+-(IBAction) saveTapped:(id)sender {
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ NSString *documentsDirectory = [paths objectAtIndex:0];
+
+ // the path to write file
+ NSString *buttonFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@", [nameField text], @"button.png"]];
+ NSString *buttonHighlightFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@", [nameField text], @"button_highlight.png"]];
+ NSString *buttonRetinaFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@", [nameField text], @"button@2x.png"]];
+ NSString *buttonRetinaHighlightFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@", [nameField text], @"button-highlight@2x.png"]];
+
+ [self saveImageToFile: buttonFile isRetina:NO];
+ [self saveImageToFile: buttonRetinaFile isRetina:YES];
+
[theButton setHighlighted:YES];
- UIGraphicsBeginImageContext(theButton.frame.size);
- theContext = UIGraphicsGetCurrentContext();
- [theButton.layer renderInContext:theContext];
- theImage = UIGraphicsGetImageFromCurrentImageContext();
- theData = UIImagePNGRepresentation(theImage);
- [theData writeToFile:buttonHighlightFile atomically:NO];
- UIGraphicsEndImageContext();
+ [self saveImageToFile: buttonHighlightFile isRetina:NO];
+ [self saveImageToFile: buttonRetinaHighlightFile isRetina:YES];
+
[theButton setHighlighted:NO];
NSString *msg = [NSString stringWithFormat:@"Wrote files to %@", documentsDirectory];
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Done" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];

No commit comments for this range

Something went wrong with that request. Please try again.