Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-06-2011, 04:15 AM   #26 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

use private messages, click on my name on the left and "Send a private message..."... I will try to take a look to the project and post the solution.
__________________
dany_dev is offline   Reply With Quote
Old 04-06-2011, 09:43 AM   #27 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

First to show the solution, some things about your code and warnings

1- warning: local declaration of 'slider' hides instance variable

you declared in your .h
IBOutlet UISlider *slider;

then in your .m you have something like
Code:
- (IBAction)hueValueChanged:(id)sender {
    
    UISlider *slider = (UISlider *)sender;
    _button.hue = slider.value;
    
}
This generate a warning because you inside that method have used the same name to identificate something that can be different, so the solution to solve these warnings are just to use another name inside the method that is not equal to your instance variable, like

Code:
- (IBAction)hueValueChanged:(id)sender {
    
    UISlider *sliderIntern = (UISlider *)sender;
    _button.hue = sliderIntern.value;
    
}
2- warning: class 'CoolButtonViewController' does not implement the 'UITextFieldDelegate' protocol

you just need to implement the delegate on your .h

Code:
@interface CoolButtonViewController : UIViewController <UITextFieldDelegate>{

...

}

3- warning: no '-renderInContext:' method found

you just need to import in your .m where use this function:
Code:
#import <QuartzCore/CALayer.h>

ok, now the problem.

you wrote on your viewcontroller.m

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	field.delegate = self;
    
    UIView *viewTmp =  [[UIView alloc] initWithFrame:CGRectMake(46, 61, 226, 46)];
    self.myView = viewTmp;
    [viewTmp release];

    _button.center = CGPointMake(120,40);
    label.center = CGPointMake(120,40);

    
    
    [myView addSubview:_button];
    [myView addSubview:label];
    [self.view addSubview:myView];
	
}
but you need something like

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	field.delegate = self;
    
    UIView *viewTmp =  [[UIView alloc] initWithFrame:CGRectMake(0, 0, _button.frame.size.width, _button.frame.size.height)];
    self.myView = viewTmp;
    [viewTmp release];
   
    
    [myView addSubview:_button];
    [myView addSubview:label];
    [self.view addSubview:myView];
	
     _button.center = CGPointMake(myView.center.x,myView.center.y);
     label.center = CGPointMake(myView.center.x,myView.center.y);
	
	myView.center =  CGPointMake(self.view.center.x,80); //change this to change your button+label position
	
	
}
the problem was that writing as you have done, you was making a uiview in another position and button doesn't have the same center, so when you go to do a screen of the view, you have just a piece of the button+label
__________________
dany_dev is offline   Reply With Quote
Old 04-06-2011, 10:03 AM   #28 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Post

Wow !
You are amazing !
Thanks to you its now al right !
I really thank you 1000000000 times.

Best Wishes ,
Sacha

Thankyou !!!
sacha1996 is offline   Reply With Quote
Old 04-15-2011, 09:20 AM   #29 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

@Dany_dev.
Hi ,
The button saves under the name button.png into the device. So you can only save it once or it will be overwritten.
Is there a way to make it save as button1.png and the second one button2.png etc. ?

Code:
- (void) saveImageToFile: (NSString *) filePath {
	UIGraphicsBeginImageContext(self.myView.frame.size);
	CGContextRef theContext = UIGraphicsGetCurrentContext();
	[self.myView.layer renderInContext:theContext];
	
	CGRect overDrawRects[] = {CGRectMake(10, 0, 1, _button.frame.size.height), CGRectMake(_button.frame.size.width - 11, 0, 1, _button.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);
		[_button.layer renderInContext:theContext];
		CGContextRestoreGState(theContext);
	}
	
	UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
	NSData *theData = UIImagePNGRepresentation(theImage);
	[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:@"button%i.png"];
	
	[self saveImageToFile: buttonFile];
	
	
	
	[_button setHighlighted:YES];
	
	
	NSString *msg = [NSString stringWithFormat:@"Wrote files to %@", documentsDirectory];
	UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Done" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
	[alertView show];
}
sacha1996 is offline   Reply With Quote
Old 04-15-2011, 09:35 AM   #30 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

ask to user the name that he like to use...

or in alternative you can do a while where check for a non-existing file.

Code:
BOOL fileExists = YES;
int number = 0;
NSString *buttonFilePath;

while(fileExists == YES){
        NSString *fileName = [NSString stringWithFormat:@"button%d.png",number];
	buttonFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
        fileExists = [[NSFileManager defaultManager] fileExistsAtPath:buttonFilePath];
        number++;
}
__________________

Last edited by dany_dev; 04-15-2011 at 09:43 AM.
dany_dev is offline   Reply With Quote
Old 04-15-2011, 09:37 AM   #31 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
ask to user the name that he like to use...

or in alternative you can do a while where check

Code:
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:somePath];
Thankyou
I want to ask the user the name he wants , are there any tutorial for this ?
I don't find it on Google
sacha1996 is offline   Reply With Quote
Old 04-15-2011, 09:41 AM   #32 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by sacha1996 View Post
Thankyou
I want to ask the user the name he wants , are there any tutorial for this ?
I don't find it on Google
you need only a uitextfield.....

for have a good UI, you can add to your UIAlertview....google UIAlertView UITextField

cocoa touch - Showing a alertview with a textbox in iPhone - Stack Overflow
__________________
dany_dev is offline   Reply With Quote
Old 04-15-2011, 10:00 AM   #33 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
ask to user the name that he like to use...

or in alternative you can do a while where check for a non-existing file.

Code:
BOOL fileExists = YES;
int number = 0;
NSString *buttonFilePath;

while(fileExists == YES){
        NSString *fileName = [NSString stringWithFormat:@"button%d.png",number];
	buttonFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
        fileExists = [[NSFileManager defaultManager] fileExistsAtPath:buttonFilePath];
        number++;
}
Hi , the user can choose the name thing is to difficult.
So I tried the code you gave me :
Code:
-(IBAction) saveTapped:(id)sender {
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	
	// the path to write file
	NSString *buttonFile = [documentsDirectory stringByAppendingPathComponent:@"button.png"];
    
    BOOL fileExists = YES;
    int number = 0;
    NSString *buttonFilePath;
    
    while(fileExists == YES){
        NSString *fileName = [NSString stringWithFormat:@"button%d.png",number];
        buttonFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
        fileExists = [[NSFileManager defaultManager] fileExistsAtPath:buttonFilePath];
        number++;
    }
	
	[self saveImageToFile: buttonFile];
	
	
	
	[_button setHighlighted:YES];
	
	
	NSString *msg = [NSString stringWithFormat:@"Wrote files to %@", documentsDirectory];
	UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Done" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
	[alertView show];
}
And it still saves in button.png and I make another one and it rewrittes the button.png on the same name.
)That's in the simulator , I don't know but maybe that changes something)
sacha1996 is offline   Reply With Quote
Old 04-15-2011, 10:28 AM   #34 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Code:
	[self saveImageToFile: buttonFilePath];
__________________
dany_dev is offline   Reply With Quote
Old 04-15-2011, 10:34 AM   #35 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
Code:
	[self saveImageToFile: buttonFilePath];
Thanks it worked !
sacha1996 is offline   Reply With Quote
Old 04-15-2011, 01:58 PM   #36 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Hi, I tried it on my ipod touch and when I save it says :
"wrote files to var/mobile/Applications/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents"
In real there is written a whole text with numbers and letters where I placed the all the x.

Why is is not saving into the the ipod camera roll in the photos app ?
Thankyou
sacha1996 is offline   Reply With Quote
Old 04-15-2011, 07:33 PM   #37 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

because you wrote the code to save the file on your documents directory...

to save to camera roll

Code:
UIImageWriteToSavedPhotosAlbum(yourUImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

  - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error 
             contextInfo:(void *)contextInfo
  {
  
  }
__________________
dany_dev is offline   Reply With Quote
Old 04-16-2011, 03:05 AM   #38 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Post

Thanks ,
But I'm quite an neewbie and I'm still learning and that's why I doesn't understand what you mean. What do I have to change to the currenct code ?

Code:
- (void) saveImageToFile: (NSString *) filePath {
	UIGraphicsBeginImageContext(self.myView.frame.size);
	CGContextRef theContext = UIGraphicsGetCurrentContext();
	[self.myView.layer renderInContext:theContext];
    
	
	CGRect overDrawRects[] = {CGRectMake(10, 0, 1, _button.frame.size.height), CGRectMake(_button.frame.size.width - 11, 0, 1, _button.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);
		[_button.layer renderInContext:theContext];
		CGContextRestoreGState(theContext);
	}
	
	UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
	NSData *theData = UIImagePNGRepresentation(theImage);
	[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:@"button.png"];
    
    BOOL fileExists = YES;
    int number = 0;
    NSString *buttonFilePath;
    
    while(fileExists == YES){
        NSString *fileName = [NSString stringWithFormat:@"button%d.png",number];
        buttonFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
        fileExists = [[NSFileManager defaultManager] fileExistsAtPath:buttonFilePath];
        number++;
    }
	
	[self saveImageToFile: buttonFilePath];
	
	
	
	[_button setHighlighted:YES];
	
	
	NSString *msg = [NSString stringWithFormat:@"Wrote files to %@", documentsDirectory];
	UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Done" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
	[alertView show];
}
sacha1996 is offline   Reply With Quote
Old 04-16-2011, 04:36 AM   #39 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Code:
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(theImage , self, nil, nil);
__________________
dany_dev is offline   Reply With Quote
Old 04-16-2011, 10:20 AM   #40 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
Code:
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(theImage , self, nil, nil);
But does this saves the two layers as the previous one ? (layer button + label) ?
sacha1996 is offline   Reply With Quote
Old 04-16-2011, 10:34 AM   #41 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

why you ask and don't try it yourself?
__________________
dany_dev is offline   Reply With Quote
Old 04-16-2011, 11:01 AM   #42 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
why you ask and don't try it yourself?
You're right , but the problem is it isn't working ...

Code :
Code:
- (void) saveImageToFile: (NSString *) filePath {
	UIGraphicsBeginImageContext(self.myView.frame.size);
	CGContextRef theContext = UIGraphicsGetCurrentContext();
	[self.myView.layer renderInContext:theContext];
    
	
	CGRect overDrawRects[] = {CGRectMake(10, 0, 1, _button.frame.size.height), CGRectMake(_button.frame.size.width - 11, 0, 1, _button.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);
		[_button.layer renderInContext:theContext];
		CGContextRestoreGState(theContext);
	}
	
	UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
	NSData *theData = UIImagePNGRepresentation(theImage);
	[theData writeToFile: filePath atomically:NO];
	UIGraphicsEndImageContext();	
}

-(IBAction) saveTapped:(id)sender {
    
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIImageWriteToSavedPhotosAlbum(theImage , self, nil, nil);
	
	NSString *msg = [NSString stringWithFormat:@"Wrote files to %@", theImage];
	UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Done" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
	[alertView show];
}
sacha1996 is offline   Reply With Quote
Old 04-16-2011, 01:15 PM   #43 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

i think you need to understand what you code, is meaningless that I write for you the code.....

hint: you need to do the same things that you do when you save your image (except save it to disk)
__________________
dany_dev is offline   Reply With Quote
Old 04-18-2011, 04:11 PM   #44 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
i think you need to understand what you code, is meaningless that I write for you the code.....

hint: you need to do the same things that you do when you save your image (except save it to disk)
Thanks , but I tried all to have to good code.
I really don't understand what I have to change
Could you please just change the code en share it on this post for the last time.
After that , I will no more ask questions about this thread
Thankyou !
sacha1996 is offline   Reply With Quote
Old 04-18-2011, 04:40 PM   #45 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Code:
- (void) saveImageToFile: (NSString *) filePath {
	UIGraphicsBeginImageContext(self.myView.frame.size);
	CGContextRef theContext = UIGraphicsGetCurrentContext();
	[self.myView.layer renderInContext:theContext];
    
	
	CGRect overDrawRects[] = {CGRectMake(10, 0, 1, _button.frame.size.height), CGRectMake(_button.frame.size.width - 11, 0, 1, _button.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);
		[_button.layer renderInContext:theContext];
		CGContextRestoreGState(theContext);
	}
	
	UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
 
        UIImageWriteToSavedPhotosAlbum(yourUImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);


	
	NSData *theData = UIImagePNGRepresentation(theImage);
	[theData writeToFile: filePath atomically:NO];
	UIGraphicsEndImageContext();	
}

  - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error 
             contextInfo:(void *)contextInfo
  {
   NSLog(@"Error didFinishSavingWithError");
  }
__________________
dany_dev is offline   Reply With Quote
Old 04-19-2011, 04:52 AM   #46 (permalink)
Registered Member
 
sacha1996's Avatar
 
Join Date: Mar 2011
Posts: 415
sacha1996 is on a distinguished road
Default

Thankyou !
sacha1996 is offline   Reply With Quote
Reply

Bookmarks

Tags
button, label, layer, save image, sdk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 369
12 members and 357 guests
condor304, dansparrow, Domele, dre, dreamdash3, ilmman, LezB44, michelle, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:35 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0