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.
Related
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;
}
}
I have 5X5 grids of buttons. If I press the button at position1 and then press the button at position2, I want the button image of position1 to be moved to the button at position2. Like as shown in the example below below, where A1 button is pressed first and then B2 button is pressed. Example:
Fig: A1 button pressed
Fig: B2 button pressed
So, the total process has two steps:
1. Prepare to move image when first button pressed
2. Move the image from first button to second button when the second button is pressed
I have set button tags for those 25 buttons shown in the 5X5 grid. Now I am having trouble to find out the logic to have the desired action.
What would be the logic in the these methods:
-(void)a1ButtonPressed:(id)sender
{
}
-(void)b2ButtonPressed:(id)sender
{
}
While the buttons have these tags:
A1.tag = 1;
B2.tag = 7;
Can anyone help? Thanks in advance.... :)
There are many ways to obtain your goal...
You can use this method to change your button image:
[aButton setImage:[UIImage imageNamed:#"anImage"] forState:UIControlStateNormal];
And you can manage your button image using a variable.
Then:
-(void)a1ButtonPressed:(id)sender
{
if (firstButton) {
// Get image to move from A1
imageToMove = [A1 imageForState:UIControlStateNormal];
// Remove image from A1
[A1 setImage:nil forState:UIControlStateNormal];
firstButton = NO;
} else {
// Put new image to A1
[A1 setImage:imageToMove forState:UIControlStateNormal];
firstButton = YES;
}
}
-(void)b2ButtonPressed:(id)sender
{
if (firstButton) {
// Get image to move from B2
imageToMove = [A1 imageForState:UIControlStateNormal];
// Remove image from B2
[B2 setImage:nil forState:UIControlStateNormal];
firstButton = NO;
} else {
// Put new image to B2
[B2 setImage:imageToMove forState:UIControlStateNormal];
firstButton = YES;
}
}
And so on...
fistButton is a BOOL that control if the button pressed is first or second.
imageToMove is a UIImage declared elsewhere that manage the image to move.
Anyway, you can use just one method for all of yours 25 buttons:
-(void)buttonPressed:(UIButton *)button
{
if (firstButton) {
// Get image to move from button
imageToMove = [button imageForState:UIControlStateNormal];
// Remove image from button
[button setImage:nil forState:UIControlStateNormal];
firstButton = NO;
} else {
// Put new image to button
[button setImage:imageToMove forState:UIControlStateNormal];
firstButton = YES;
}
}
If you want to give animation need to do UIView animation that is core animation
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
//set animation value means the next postion where u want to move object
[UIView commitAnimations];
please like it
Just use one method for all the buttons, simple logic something like this
-(void)buttonPressed:(UIButton *)btn {
if (buttonPressed) {//second press
[initialBtn setImage:blankImage forControlState:UIControlStateNormal];
[btn setImage:buttonImage forControlState:UIControlStateNormal];
buttonPressed=NO;
} else {//first press
buttonImage=[btn imageForState:UIControlStateNormal];
buttonPressed=YES;
initialBtn=btn;
}
In your header you would have
BOOL buttonPressed;
UIImage *buttonImage;
UIButton *initialBtn;
This would also work if the user pressed the same button twice, cancelling their selection.
Hope this helps you!
An alternative to accomplish this, add all the buttons in an array when creating the buttons and set each button a tag.Then store the tag of both pressed button.Use the previous pressed tag to read the button using [buttonarray objectAtIndex:previous.tag] and set to nil and to current tag set background image of previous button.
I have a smaller UIButton which is on top of a larger UIButton.
The problem right now is that if I tap the smaller UIButton, it also will trigger the larger UIButton. The code I'm using to determine if the buttons were tapped is:
if(CGRectContainsPoint(button1.frame, location)) {
}
Is there a property of the buttons or some automated way to make the smaller button not effect the larger button?
I know I could alter the code above to say if its within button1's frame and not within button2, but is there another way to do it?
UIControl (which is the superclass of UIButton) passes itself as the only parameter to its target using the action selector. Make use it, it's there for exactly these cases!
[smallButton addTarget:self action:#selector(doStuff:) forControlEvents:UIControlEventTouchUpInside];
[bigButton addTarget:self action:#selector(doStuff:) forControlEvents:UIControlEventTouchUpInside];
// ...
- (void) doStuff:(UIButton *)btn
{
if (btn == smallButton)
{
// smaller button was clicked
}
else
{
// bigger button was clicked
}
}
I need a UIButton to act as a Radio button (selection button). When the user
clicks on the button, the color should change (to indicate that the user
clicked this button), and when the user clicks the same button again (the already selected
button) the color of the button should change to the default color indicating
that the button was un-selected.
How can i do this programatically ?
There might be other alternatives to do this, but i require to use the button
to do this.
You can specify different images for selected and normal button states:
[btnName setImage:selectedImage forState:UIControlStateSelected];
[btnName setImage:normalimage forState:UIControlStateNormal];
And then in button's action method simply toggle button's state between normal and selected:
- (void) buttonAction:(UIButton*)sender{
sender.selected = !sender.selected;
}
Put the below code in your button action.
if([btnName isSelected]) {
[btnName setImage:#"SelectedImage" forState:UIControlStateNormal];
[btnName setSelected:NO];
} else {
[btnName setImage:#"deSelectedImage" forState:UIControlStateNormal];
[btnName setSelected:YES];
}
Hope it will be useful.
Follow below link:
Radio Button in iPhone
I am creating an iphone app where I have used 25 buttons and each button has been shown a background image in its normal mode.I have also set another image on the highlighted mode of the button.
Initially button will be shown in its normal mode
now I want that when a button is pressed then button should change to its highlighted state so as the other image will be displayed there.
I have done so by doing:
button.highlighted = YES;
Its working but its sets the highlighted image for a fraction and then again normal state of the button come back. I use the following code to create the buttons.
for (int i=0; i<25; i++) {
if (i > 0) {
if (i%5 == 0) {
xaxis = 28;
yaxis = yaxis+42;
}
}
iconButton[i] = [UIButton buttonWithType:UIButtonTypeCustom];
iconButton[i].frame = CGRectMake(xaxis, yaxis, 50, 40);
[iconButton[i] setBackgroundImage:[iconArray objectAtIndex:random] forState:UIControlStateNormal];
[iconButton[i] setBackgroundImage:[tapedIconArray objectAtIndex:random] forState:UIControlStateHighlighted];
[iconButton[i] addTarget:self action:#selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:iconButton[i]];
xaxis = xaxis+53;
}
How can i hold the state of the button, I even tried with timer but app get crashed then.
Please help me
Many Thanks in advance
I am not sure of this but try it by setting image for button's UIControlStateSelected
i.e.
[btn setImage:[UIImage imageNamed:#"selectedImage.png"] forState:UIControlStateSelected];