Save UItextfield on UIImage - iphone

I have an iOS application that allow user to write text with custom fonts on images , there is save button , when press this button the text is save and burn on the image but it's not save correctly , the text drop down .. please see the screen shot :
The problem is in this code , but I don't how I can fix it , I want to save text on image without moving down or up .
this is my code .
-(void)realSave{
// Request to save the image to camera roll
for (UIView *view in [self.view subviews]) {
if (view.tag>=MIN_TAG_TEXT_BUTTON && view.tag<MAX_TAG_TEXT_BUTTON) {
NSLog(#"TAG:%d",view.tag);
//add text to image at here
if ([self.tempStr length] > 0) {
CATextLayer *normalTextLayer = [self customCATextLayerwithTag:view.tag];
[drawImage.layer addSublayer:normalTextLayer];
// [drawImage setImage:[self burnLayerIntoImage:drawImage.layer withImage:drawImage.image]];
//[normalTextLayer removeFromSuperlayer];
}
else{
[drawImage setImage:[self burnTextIntoImage:view withImage:drawImage.image]];
}
[view removeFromSuperview];
saveBacking.hidden=YES;//ongraph added
saveLabel.hidden=YES;//ongraph added
spinner.hidden=YES; //ongraph added
[spinner stopAnimating]; //ongraph added
}
}
appDelegate.__is_saved_image = TRUE;//ongraph added
appDelegate.__saved_image = drawImage.image;//ongraph added
currentTagAddTextButton=MIN_TAG_TEXT_BUTTON;
//UIImageWriteToSavedPhotosAlbum(drawImage.image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);//ongraph uncommented
}

UIGraphicsBeginImageContext(self.yourView.bounds.size);
[self.yourView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *shareImage = UIGraphicsGetImageFromCurrentImageContext();
shareImage is UIImage , you can share and save it .. hope it can help you.

#user1288377 try this
btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
[btn1 setFrame:CGRectMake(367, 117, 97, 25)];
[btn1 addTarget:self action:#selector(saveImage:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn1];
-(void)saveImage{/*saveImageMethod*/}

Related

How to make expandable/collapsable ImageView

I have many textViews on top of a scrollView and every textView has a custom button over it so that when user click that textView it should expand and when it click back then it should collapse to previous position.
what I'm thinking of doing is hide the smallTextView and show the expandedTextView when button is pressed and when the button is pressed i want to hide expandedtextView n show the smallTextView. but I don't know how I should do it. any help will be appreciated.
Here is my code:
-
(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = #"Demo";
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
for (int i=0;i<[appDelegate.serverResponseArray count];i++)
{
self.expandTextView = [[UITextView alloc] init];
[self.expandTextView setFrame:CGRectMake(8.0f, i*50.0f+10.0f, 270.0f, 40.0f)];
[self.expandTextView setBackgroundColor:[UIColor grayColor]];
[self.expandTextView setFont:[UIFont fontWithName:#"helvetica" size:12]];
[self.expandTextView setText:#"Welcome!!!"];
[self.expandTextView setTextColor:[UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:1]];
[self.expandTextView setUserInteractionEnabled:NO];
[self.scrollView addSubview:self.expandTextView];
self.expandTextView = nil;
self.expandButton = [[UIButton alloc]initWithFrame:CGRectMake(8.0f, i*50.0f+1.0f, 270.0f, 60.0f)];
[self.expandButton setBackgroundColor:[UIColor clearColor]];
[self.expandButton addTarget:self action:#selector(textButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.expandButton.tag = i;
[self.scrollView addSubview:self.expandButton];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(278.0f, i*50.0f+10.0f, 14.0f, 40.0f)];
[imageView setBackgroundColor:[UIColor grayColor]];
[imageView setImage:[UIImage imageNamed:#"arrow.png"]];
[self.scrollView addSubview:imageView];
imageView = nil;
}
float maxHeight = 0;
for(UIView *v in [self.scrollView subviews])
{
if(v.frame.origin.x + v.frame.size.height > maxHeight)
maxHeight = v.frame.origin.x + v.frame.size.height;
}
self.scrollView.contentSize = CGSizeMake(_scrollView.frame.size.width, maxHeight+2570);
}
-(IBAction)textButtonClicked:(id)sender
{
NSLog(#"%#",sender);
}
and how do I know which button is getting pressed.
To know which button press you have to assign tag value to your button then
-(IBAction)textButtonClicked:(id)sender
{
UIButton *btn=(UIButton*)sender;
NSLog(#"Tag of button = %d",btn.tag);
}
And i suggest you to change frame of your existing imageView instead of using other image view(hide and show)
First of all , I'd suggest you to use UITableView instead of UIImageView and then implement Expandable and Collapsible UITableViewCell.
There are lots of Tutorial to implement this Functionality. Simply Google it and you will have plenty of solutions for that.
For Example : Expandable/Collapsible Table For iOS
Check this Sample Code provided by Apple : Table View Animations and Gestures.
The Best way is Take UITableView and Put your images on Cell of UITableView and change size of cell when your click on it, i give you simple example for how to create expandable UITableViewCell.
http://www.roostersoftstudios.com/2011/04/14/iphone-uitableview-with-animated-expanding-cells/

set iphone wallpaper with array of buttons objective c

Hi. I am developing an app and I would like to set the background in the app itself.
Now I created an array of buttons using a for loop and setting tags, but for some reason when I click the buttons nothing happens.
This is where the buttons are created:
-(void)showSettings {
[[objc_getClass("DreamBoard") sharedInstance] hideAllExcept:mainView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
if(toggled){
photos = [[NSArray arrayWithObjects:
[UIImage imageWithContentsOfFile:#"/var/mobile/Library/iZoon/Images/Wallpapers/Wallpaper1.png"],
[UIImage imageWithContentsOfFile:#"/var/mobile/Library/iZoon/Images/Wallpapers/Wallpaper2.png"],
[UIImage imageWithContentsOfFile:#"/var/mobile/Library/iZoon/Images/Wallpapers/Wallpaper3.png"],
[UIImage imageWithContentsOfFile:#"/var/mobile/Library/iZoon/Images/Wallpapers/Wallpaper4.png"],
nil] retain];
w=0;
for ( UIImage *image in photos )
{
for (l = 0; l<(int)photos.count; l++)
{
wallpaperButton = [[UIButton alloc] initWithFrame:CGRectMake(5,130+150*w,150,150)];
wallpaperButton.tag = l;
[wallpaperButton setImage:image forState:UIControlStateNormal];
[wallpaperButton addTarget:self action:#selector(setWallpaper) forControlEvents:UIControlEventTouchDown];
[settingsMenu addSubview: wallpaperButton];
[wallpaperButton release];
}
w++;
}
Here is the function to set the wallpaper:
-(void)setWallpaper {
UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
if ([wallpaperButton tag] == 1) {
bgView.image = [UIImage imageWithContentsOfFile:#"/var/mobile/Library/iZoon/Images/Wallpapers/Wallpaper1.png"];
}
else if ([wallpaperButton tag] == 0) {
bgView.image = [UIImage imageWithContentsOfFile:#"/var/mobile/Library/iZoon/Wallpapers/Wallpaper2.png"];
}
else if ([wallpaperButton tag] == 2) {
bgView.image = [UIImage imageWithContentsOfFile:#"/var/mobile/Library/iZoon/ Wallpapers/Wallpaper3.png"];
}
else if ([wallpaperButton tag] == 3) {
bgView.image = [UIImage imageWithContentsOfFile:#"/var/mobile/Library/iZoon/Wallpapers/Wallpaper4.png"];
}
[mainView insertSubview:bgView atIndex:0];
[bgView release];
}
Now the buttons display correctly but they don't do anything.
Any help is appreciated. Thanks.
Add an NSLog statement to see if the setWallpaper method is being called. If it is, then i think this might be a fix:
If you just add the images to your XCode Project, you can just get them by their name. Make sure you check the "copy files to project folder if needed" box when you drag the images into the project. Then to get the image you can just do this:
if ([wallpaperButton tag] == 1) {
bgView.image = [UIImage imageNamed:#"Wallpaper1.png"];
}
.
.
.
[self.view addSubview:bgView];
Also, you should be aware that unless your app is hiding the status bar (the one with the battery and clock) then your images should actually have a height of 460 because 20px are used up by that.

Subview position on the parent view iPhone

I m using a menu bar like this (using UIBUTTONS on an ImageView)
Now what I required to do is that when I click on each button a popover (subview) should come up like:
How can I do that?
My second question is that when i click on the same button or anywhere else on the view then the popover should get hide and if i click on another menu button popover should get hide from previous button and should be shown on other button...
My project is already created with UIviewcontroller, so i think it would be much difficult to include the tab bars
any help please ...
-(IBAction)buttonNotify:(id)sender{
popOver.frame = CGRectMake(173, 385, 88, 33);
[self.view addSubview:popOver];
}
In .h file of your ViewController declare
UIImageView *popupView`;
In .m file in initialisation initialise it, something like
popupView = [[UIImageView alloc] initWithImage:#"your_image.png"];
popUpView.frame = //some CGRect here//;
popUpView.hidden = YES;
[self.view addsubView:popupView];
[popupView release];
Also when you create your buttons you do it like this, yep?
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = //some CGRect here//;
btn.tag = 1; // here you can set numeric tag for all your buttons
[btn addTarget:self action:#selector(buttonHandler:)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[btn release]
And implement method
-(void)buttonHandler:(id)sender
{
//sender here is your button object
//so you can take it's tag or frame or something else to set frame of popupView
popUpView.frame = //some rect
popUpView.hidden = NO;
}
And you when you handle touch on your view, set
popupView.hidden = YES to hide it
Also you can add some animation.
menu1Btn.tag = 0;
menu2Btn.tag = 1;
....
-(IBAction)buttonNotify:(id)sender{
int tag = [sender tag];
[popOver removeFromSuperView];
if(tag ==0){
popOver.frame = CGRectMake(0, 385, 88, 33);
[self.view addSubview:popOver];
}
else if(tag ==1){
popOver.frame = CGRectMake(40, 385, 88, 33);
[self.view addSubview:popOver];
}
else if(tag ==2){
popOver.frame = CGRectMake(80, 385, 88, 33);
[self.view addSubview:popOver];
}
......
}

UIWebView Crash?

Hii Friends,
the application is that using a imageviewer of a which had placed a Ad at Bottom where when clicked will move to php registration page,when user closes the reg.View it will go back to imageviewer, as i using Three20UI Library for the PhotoViewer,
the code as follows,
-(void) actionCall {
if(isValue) {
NSLog(#"removeView from WEbview");
UIView *tmpView = (UIView *)[self.view viewWithTag:10];
[tmpView removeFromSuperview];
[custView removeFromSuperview];
isValue = FALSE;
}
if(changeViewSize == 1)
{
myView.frame = CGRectMake(0, 365, 360, 72);
}
}
[cusBtn addTarget:self action:#selector(actionCall) forControlEvents:UIControlEventTouchUpInside];
the program crashes when closebtn is clicked, Any Solutions Plz.
Try this:
-(void) actionCall:(id)sender {
...
[cusBtn addTarget:self action:#selector(actionCall:) forControlEvents:UIControlEventTouchUpInside];

Changing image on UIButton when user presses that button on an iPhone

I want to change the image on UIButton, when User presses that button. So, I wrote
btnthumbnail2 setImage:[UIImage imageNamed:#"leaderboard_ov.png"] forState:UIControlStateNormal];
and after that I changed the view.
The image is changing but not display the changed image.I think the controll goes to next view tha's why it is happening. But I want to show the change, How can I do this?? Plz help me for this..
I am using Interface Builder, in which I added a UIButton to the view.
I defined the button selected by default and selected my image for the selected state (Use drop-down list in Inspector window to choose "Selected State Configuration" before selecting the image).
Create an IBAction in the controller and connect the button to that action.
Then see the code below:
-(IBAction) toggleUIButtonImage:(id)sender{
if ([sender isSelected]) {
[sender setImage:unselectedImage forState:UIControlStateNormal];
[sender setSelected:NO];
} else {
[sender setImage:selectedImage forState:UIControlStateSelected];
[sender setSelected:YES];
}
}
This is the simplest way that I am doing it and it works every time
-(void)buttonTouched:(id)sender
{
UIButton *btn = (UIButton *)sender;
if( [[btn imageForState:UIControlStateNormal] isEqual:[UIImage imageNamed:#"icon-Locked.png"]])
{
[btn setImage:[UIImage imageNamed:#"icon-Unlocked.png"] forState:UIControlStateNormal];
// other statements
}
else
{
[btn setImage:[UIImage imageNamed:#"icon-Locked.png"] forState:UIControlStateNormal];
// other statements
}
}
You can use other similar checks for other states such as SELECTED, ENABLED, HIGHLIGHTED.
The code you have there should work fine, but I'm guessing that the button image doesn't appear changed until the next run through the event loop, so you don't see it before the view gets switched out.
It's kind of a hack, but you could try delaying the view change just slightly so that the button will update.
So instead of this:
[btnthumbnail2 setImage:[UIImage imageNamed:#"leaderboard_ov.png"] forState:UIControlStateNormal];
[self showMyOtherView];
Try this:
[btnthumbnail2 setImage:[UIImage imageNamed:#"leaderboard_ov.png"] forState:UIControlStateNormal];
[self performSelector:#selector(showMyOtherView) withObject:self afterDelay:0.01];
To change the image for the selected state you have to call setImage for state UIControlStateSelected. You can set separate images for different states (Normal, Highlighted, Disabled, Selected, etc).
If you want to change the image when the button is clicked, this way, works perfectly:
-(IBAction)buttonClicked: (id)sender
{
UIButton *buttonObj = (UIButton*)sender;
[buttonObj setBackgroundImage:[UIImage imageNamed:#"myImage.png"]
forState:UIControlStateNormal];
}
The simplest way to accomplish this is to simply set the highlighted image in Interface Builder.
Building on Nicsoft's answer.
-(void)viewDidLoad {
[super viewDidLoad];
[self.button setImage:[UIImage imageNamed:#"unselectedImageName"] forState:UIControlStateNormal];
[self.button setImage:[UIImage imageNamed:#"selectedImageName"] forState:UIControlStateSelected];
}
-(IBAction)toggleButton:(UIButton *)sender {
sender.selected = !sender.selected;
// Add logic here
}
I wrote code that does exactly this last night, and I didn't have to resort to any strange delaying tactics. In this particular case, I'm doing it from inside a tableViewCell. This is more code than you asked for, but it shows the whole process I used. As you can see, I chose not to have any special image for the period of time DURING a button touch.
// Button set up, inside cellForRowAtIndexPath:
// imageFrame is just the rect that you want the button to occupy
[self setFavorite:[[UIButton alloc] initWithFrame:imageFrame]];
[[self favorite] addTarget:self action:#selector(toggleFavorite:)
forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:[self favorite]];
[self draw];
// definition of the callback specified above
- (void) toggleFavorite:(id) sender {
if (favoriteState == 0 ){
favoriteState = 1;
} else {
favoriteState = 0;
}
[self draw];
}
// the draw method, to set the images
// favOn and favOff are statically defined at the top of the class
- (void) draw {
if (favoriteState != 0) {
[[self favorite] setBackgroundImage:favOn forState:UIControlStateNormal];
[[self favorite] setBackgroundImage:favOn forState:UIControlStateHighlighted];
} else {
[[self favorite] setBackgroundImage:favOff forState:UIControlStateNormal];
[[self favorite] setBackgroundImage:favOff forState:UIControlStateHighlighted];
}
}
Hate to add to the plethora of answers, but:
Select images in IB for the button's default and selected states.
Connect an IBAction and keep it simple.
#IBAction func buttonTapped(sender: UIButton){sender.selected = !sender.selected}
Done.