How to select and deselect the thumbnail images in iphone - iphone

I am new to i phone programming.How to select and deselect the thumbnail images.Right now what i did i have taken custom button using that i am adding custom image to thumbnails,it is mainly used for i can know that these thumbnail images are selected.like that,if select any thumbnail image means,custom button is attaching to each every selected thumbnail image.
Now what i want means if i again click on same image means i want remove custom button image form the selected thumbnail.again if i selected means it have attach that custom button image and if again select on same image means i have remove that custom button image form the thumbnail.Can any body tell what logic i have use here.
Here is my code
- (void)handleThumbClick:(id)sender
{
NSLog(#"yes selected");
FGalleryPhotoView *photoView = (FGalleryPhotoView*)[(UIButton*)sender superview];
customBadge1 = [CustomBadge customBadgeWithString:#"1"
withStringColor:[UIColor greenColor]
withInsetColor:[UIColor redColor]
withBadgeFrame:YES
withBadgeFrameColor:[UIColor grayColor]
withScale:1.0
withShining:YES];
b =[UIButton buttonWithType:UIButtonTypeCustom];
b.frame = CGRectMake(0,0, 100,100);
[b setImage:[UIImage imageNamed:#"Overlay#2x.png"] forState:UIControlStateNormal];
[b setTitle:#"1" forState:UIControlStateNormal];
// [b setTag:4];
NSLog(#"Thumb click Fgallerview controller");
[photoView addSubview:b];
[photoView addSubview:customBadge1];
}
The above code for if click on any thumbnail means its attaching the custom button image to that thumbnail image.Now what i want means if again if click on same thumbnail i have remove that custom thumbnail image.
For example in thumbnail view i have 10 images is displaying now i want to select only 5 images if click on any 5 thumbnail means its attaching custom button image to 5 selected images.Now what i want means if want in selected 5 thumbnail images having custom button image.now if i select any selected image means i have to uncheck that selected image ,means i want to remove that custom button image form the selected thumbnail.
Can any body tell me how to do this
And one more thing i now that by using ELCimagepickercontroller we can able to select multiple images,but that only gallery images but here i am displaying from private document directory folder images..Please help meee
Thanks
Aslam

Set thumbnail image as setBackgroundImage and set initial tag=0;
-(IBAction)handleThumbClick:(id)sender
{
UIButton *btn = (UIButton*)sender;
if (btn.tag==0)
{
[btn setImage:[UIImage imageNamed:#"Default.png"] forState:UIControlStateNormal];
btn.tag=1;
}
else{
[btn setImage:nil forState:UIControlStateNormal];
btn.tag=0;
}
}

Related

Custom UIButton image iOS

Is it possible to have a custom UIButton that has an image covering only half of it?
I imagine it would be something like this:
UIButton *someButton = [UIButton buttonWithType:UIButtonTypeCustom];
[someButton setBackgroundImage:[UIImage imageNamed:#"buttonPicture"]];
/* Then there must be some property I can set that prevents the button from stretching the image?? */
.
.
.
I want to have a 50x100px button which only has a 50x50px image on the top half, and to be transparent on the bottom half.
I know how to create a custom button and everything. Im just woondering what the property is that controls the stretching of the backgroundImage.
Thanks!
Use
[someButton setImage:[UIImage imageNamed:#"buttonPicture"] forState: UIControlStateNormal];
someButton.imageEdgeInsets = UIEdgeInsetsMake(-50, 0, 0, 0);
I think you could:
create your button image as a 50x100px image (same size as the button);
make this image be half transparent (PNG with alpha),
instead of trying to assign the button a smaller image covering only half of it and prevent stretching.

UIButton tags in iPhone

I have 2 button objects (UIButton *obtn,*ebtn), I have created 12 buttons(6 buttons with 6 tag values for obtn, 6 buttons with 6 tag values for ebtn)... I have a single btnClick: method for all those 12 buttons... when i click on a button of tag value 1... Iam getting the properties of selected button to another button by using sender... I want to get the properties of unselected button (Example obtn object with tag value 3) into another button How can i get it...?
My Direct Question is: How to assign the properties of a button with a tag value to another button when it is in unselected state...
It sounds like you want to be able to get a pointer to a button with a certain tag, and at the moment all you can do is get the button that has sent you the action.
The method you are looking for is viewWithTag:. This will get you a button (or any other view) with the tag you want. You pass this method to the superview of the button. So, in your action method (assuming all buttons are in the same superview):
UIView *superview = [sender superview];
UIButton *otherButton = [superview viewWithTag:3];
You then have sender, which is the button that was tapped, and otherButton, which is the button with tag 3. You can modify each one as you wish.
// Create textfield 5
btn_select_Country = [UIButton buttonWithType:UIButtonTypeCustom];
//btn_select_Client = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn_select_Country.frame = CGRectMake(BTN_X_CORD, 228, BTN_WIDTH, BTN_HEIGHT);
btn_select_Country.tag = 1;
// [btn_select_Client setTitle:#"Button One" forState:UIControlStateNormal];
[btn_select_Country addTarget:self action:#selector(countryListBtnTap:) forControlEvents:UIControlEventTouchUpInside];
btn_Image_Select_Country= [UIImage imageNamed:#"drop-down.png"];
[btn_select_Country setImage:btn_Image_Select_Country forState:UIControlStateNormal];
//btn_select_Client.tag=1205;
[scrollview addSubview:btn_select_Country];
- (IBAction)currencyListBtnTap:(id)sender;
{
button_Number = [sender tag];
[self allTextFeildResignFirstResponder];
}

How to show a image background when button is scelected or clicked

i have this code in the button click to show selection image when the button is clicked
UIImage *img1 = [UIImage imageNamed:#"settingpress.png"];
[_btnclick setImage:img1 forState:(UIControlStateHighlighted+UIControlStateSelected)];
[img1 release];
but i didn't get the image ,my button is a UIButton in xib with custom button not the Roundrect.what is the error in my code.
thanks in advance.
You have to use background Image and the | separator:
[_btnclick setBAckgroundImage:img1 forState:(UIControlStateHighlighted|UIControlStateSelected)];

how to keep image on button as selected on cell in iphone

my code is working till here
-(void)imageStatusChanged:(id)sender{
if(mode.IsCompleted==TRUE){
mode.IsCompleted=FALSE;
}
else {
mode.IsCompleted=TRUE;
}
if([imagemodal UpdateStatus:mode.modeId :mode.IsCompleted]==TRUE)
{
//update the image
if (mode.IsCompleted) {
[modeCompletedButton setImage:[UIImage imageNamed:#"Pad-Checkbox-Done-N.png"] forState:UIControlStateNormal];
[modeCompletedButton setShowsTouchWhenHighlighted:YES];
}
else{
[modeCompletedButton setImage:[UIImage imageNamed:#"Pad-Checkbox-Inactive-N.png"] forState:UIControlStateNormal];
[modeCompletedButton setShowsTouchWhenHighlighted:YES];
}
}
}
if i touch the button the image is changing it working good.But for eg if i click any button the image is change if go other page and come again same page where i selected button for tick and untick then my my image is disapper .On selected i stor the bool value 0 is untick and 1 is tick image what i have to do in my code so when i close application and again run then selected image should display how to do please help me
better to use NSUserDefaults, same case of problem is in my app but it's in table cell. In table view using indexpath.

Want to have view as Image Attached using UITableView

Hi
In my app, i have a requirement to make this grid view..type....i want to do it by UITableView...(Although done via scroll view)
My Query is , by using custom cell, in 1 row, there will be 1 custom cell with 4 image view in it...
so now on image tapping how will i know which image inside cell is tapped????
or second option i thought..as each image as custom cell..but dont know how to proceed furthur....as how can we get 2 adjacent cell in 1 row????
Also wanna know which method is better...as this grid view will be containing 50 images around....and on tapping bigger view opens with scrolling...
Thanks
What you can do is create a custom UIButton inside the UIView and set a background image and a selector.
Something like this :
UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(0, 0, 24, 24)];
[button addTarget:self action:#selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundImage:[UIImage imageNamed:#"someImage.png"] forState:UIControlStateNormal];
[buttonHolder addSubview:button]; //buttonHolder will be one of the UIView in your cell
i have create image gallery view using scroll view gallery view
if you want to make in table view you have to create custom cell with 4 image view and a single button each image attached with image tag when a button pressed it get the tag number and you can find which of image button is clicked.