Making a button invisible after clicking it? - ios

I would like to know how to make a button that starts the gameplay and right after the gameplay starts the button must disappear from the view and can't be touchable.
Does anyone know how to do this?

you can also do it by setting its alpha value to zero. try this!
[self.buttonName setAlpha:0];
and again on changing it to one will unhide the button.
[self.buttonName setAlpha:1];
hope this serves your purpose. Happy coding!.

I think it is quite simple make sure you have both the outlet and Action property of UIButton. In the .h file.
#property(weak,nonatomic)UIButton *clickMeButton;
-(IBAction)clickMe:(id)sender;
Now implement the hide code in the .m file
-(IBAction)clickMe:(id)sender
{
clickMeButton.hidden=YES;
}
I hope this will work for you .

Related

Adding a button at the bottom of JSQMessagesCollectionView

I am newbie in iOS. Sorry for my English. Actually I want a button at the bottom of my JSQMessagesCollectionViewenter image description here. I have tried to put it like "drag" and "drop". But it doesn't work there. I know there must be a silly mistake which I am doing with the logic. But I need someone's help to guide me the correct way to do it. Thanks in advance. :)
JSQMessagesCollectionViewController was deprecated I would suggest you to replace it with something else as soon as you can. MessageKit for example.
THis is out side the scope of the JSQ library. I guess it could be in the scope of the library depending on what the button does but JSQ really only helps when it comes to chat. So if the CollectionView you have displayed is the chat part of your app you could add a button in the inputBar but the screen shot does not seem to indicate that. Other wise what you are doing should be pretty strait forward. You could add a button via StoryBoard add Constraints to pin it to the bottom of your screen and hook up the outlets for it to do the action you desire. Or you could do it programmatically in your ViewController. That is about all the help that can be provided with the information given. If share more of you code we may be able to provide more guidance.
Daniel is saying right this is out of the scope of the jsq library still if you want to add Button or other view i will suggest you to add it programmatically to your JSQMessagesViewController SubClass like if i am understanding your question you can add view above the JSQMessagesViewController's Subclass's inputToolBar as -
UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, self.inputToolbar.frame.origin.y - self.inputToolbar.frame.size.height, self.view.frame.size.width, 55)];
v.backgroundColor = [UIColor redColor];
[self.view addSubview:v];
now then you have to change the position of view / button each time keyboard appear or disappear as inputbar becomes first responder. As far as i am understanding your question i think this will help.
Although You can also change the XIB of InputToolBar and Can customize your Button in storyboard(xib) then do changes in the class of InputToolBar according to your needs.

Remove Object out of subview

Hey guys I added a UIImageView to the subview and want to remove it after a couple of seconds.
self.view.addSubview(car)
Now I want to remove the image completely. I tried something like:
self.view.delete(car)
But than I get a really long error when I press the button, which should remove the image.
I hope you can help me out.
-Lukas
removeFromSuperview is your way to go.
car.removeFromSuperview()
Methods to manage the view hierarchy are documented for UIView.

UIButton style gone after segue

I'm trying to fix a problem that does not make any sense to me.
I'm applying a style to 3 of my buttons. When I click another one, there is a segue. When I dismiss the viewController, the style is not applied to my 3 previous buttons..until I click again ! I thought it was my configuration with line code that was wrong so I've deleted every customizations.
I directly configure buttons from the interface builder.
Here it my segue code even if I think it's not useful.
- (IBAction)addContact:(id)sender {
[self performSegueWithIdentifier:#"FriendsToAddFriends" sender:sender];
}
I've added some picture to show my problem :
The strangest part is when I'm back to the first page, when I click without release my click, the style comes back. It's the same for the whole 3 buttons.
I don't have any other idea to fix it. Does someone have ?
Thank you a lot in advance !
Problem solved with this code :
for (UIButton* button in buttons) {
[button.titleLabel setTextAlignment:NSTextAlignmentNatural];
}
I applied it on each following methods :
viewWillDisappear
viewWillAppear
I still don't know why this alignment change when the view will disappear.
It seems working for now.
I hope it will help someone else.

iOS Retractable Menu

I am currently developing an app that contains a music player. As of now it has a play, pause, & a select song button that shows the current song playing. Right now, the player is always on the screen. I want to make it so theres a button in the middle of the page so that when users click that, the whole media player with the play, pause, and select song button/icon will appear. When they click on that middle button again it shall hide those icons.
If anybody could point me in the right direction whether it be tutorials already out, or other discussions (I could not find any ones really) that would be awesome!
NOTE: I'm not trying to make the popover menu that facebook uses. This menu/audio player will expand/retract horizontally over the current view
Thank you in advance!!!!
Sounds like you need to look into the .hidden property of view objects (allows you to make views visible/not-visible), and possibly the ability to move views around on the screen with the .frame property (setting location, height/width).
Without some more detailed information about the effect you're trying to achieve, it's difficult to say more than that. If you use interface builder to set up the view/UI-objects you want to display, you can simply set the base view to hidden in interface builder and then when the user clicks your button set .hidden=NO for that view.
Note: to be able to show/hide everything as a unit like this, I'm assuming that you use a single UIView object in interface builder as the container (sized and placed where you want it) and then add your controller buttons as sub-objects inside that single view. This allows you to show/hide everything by just setting .hidden property for the containing view.
I'm not exactly sure what visual effect your looking for, but I think you already said it - just hide them.
You can do that a couple of ways.
One simple way is just to put those elements inside of their own view. Use a storyboard or xib file. Put your buttons and controls you want to hide show in a view.
Then create a reference in your view controller to that view. call it controlsView.
#property (strong,nonatomic) IBOutlet UIView *controlsView;
Make sure you connect that view.
Then when the button is pushed, just hide that entire view:
self.controlsView.hidden = YES;
When pushed again, show it:
self.controlsView.hidden = NO;
If you want a bit smoother look and feel, wrap it in an animation like this:
//to hide
[UIView animateWithDuration:2 animations:^{
[self.controlsView setAlpha:0];
} completion {
self.controlsView.hidden = YES;
}];
//to show
self.controlsView.alpha = 0;
self.controlsView.hidden = NO;
[UIView animateWithDuration:2 animations:^{
[self.controlsView setAlpha:1.0];
} completion {
}];
hope that helps

Adding a custom UIButton and action to a view in window app delegate (ios)

I am working on a tab bar application which needs a global title bar with a setttings button attached. I have achieved adding an imageview to the main window, then a label, another image, and finally a button. However, I cannot get this button to fire an action. it is set up like this:
[settingsButton addTarget:self action:#selector(settings) forControlEvents:UIControlEventTouchupInside];
Then the action defined like:
-(void)settings{
NSLog(#"please do something");
}
However nothing happens, the image doesn't even change like it is being pressed. Can i not define buttons in the app delegate this way? is it because the target is not something that is control based? i tried different targets but i must not fully understand what setting a target is. thanks for any help.
P.S.- i tried setting up the method like so as well:
-(void) settings:(id)sender{
}
and calling it by replacing the action with #selector(settings:) to no avail. Thank you.
I solved it. I forgot I changed the view behind the button to a UIImageView. I can't believe I didn't think of this before since this same issue cost me 2 hours the other day. When you have an imageView always remember to set this flag if you want stuff on it:
(someImageView).userInteractionEnabled = YES;
Hopefully I save someone an hour or two of needless headaches.
P.S. Thanks for the speedy comment !

Resources