Show an image thats hidden thats on a view controller from another view controller that has a button - ios

I have two squares on one ViewController which are ImageViews. One is white the other black. At any time one is hidden, the other is one shown. I want to switch which one is shown based on if the user presses a Button that's either white or black and is on another ViewController. I want to show this when I press on a Button to go back to the first ViewController and either the black square is showing or white square is showing depending on which Button I selected from a Button that's on another ViewController.

You can keep track of the state of the ImageViews (on or off) in NSUserDefaults or a Singleton from the first controller when pressing the associated button. Then grab this state from the second view controller so you know what to display.

Related

Add an inputview to UIButton for on click event iOS

I am building a page for a Swift iOS app and I want the user to be able to specify the date range for a graph. At the top of my graph I want the user to select a date range by clicking on a button which will gray out the screen and bring up a picker view on the bottom of the screen to select the date range. It's very similar to how the myfitnesspal app does it (below):
As you can see when they click on the calendar button it brings up a pickerview while graying out the rest of the screen and only recognizes touches to the pickerview. I basically want to replicate this kind of method that allows me to bring up a custom picker when a button is clicked.
I have tried using UIActionSheet however that is now deprecated and I've read that an action sheet should not be used for this kind of functionality.
You can do this by designing a view controller such that-
It has a background view that covers entire screen with background color as black with some alpha say 0.3. This view will serve to block out any touches on the views behind it. Basically it will have that translucent background effect.
Have your actual view such as picker view as a sibling of this, add other siblings like the cross button, etc. You can use the cross button to initiate closing of the view.
Present this controller as a child view controller on the controller where you need this.

Swift - create a back button without navigation controller

I have an app that has a toolbar, but I don't want the bar at the top, in order to free more viewing space. Therefore I have decided not to use a navigation controller. I'd like to add a back button to the toolbar. How would I go about this?
Adding the button is easy enough, and setting the action to performSegueWithIdentifier is all fine, but what happens is that the previous view just gets loaded again, rather than show it as it was, like a true back button. So if I tap on the 10th row on a tableView and go to a new page, when I press the back button it loads the view from the top again, instead of showing it as where I scrolled down to last.
Even though you don't want a UINavigationBar, you do want a UINavigationController in this case, because it manages the 'back stack' exactly the way you want it. Just hide its navigation bar by setting its navigationBarHidden property to true (in the Storyboard or in the viewDidLoad function of the root view controller).
You can then use navigationController.popViewController(true) as normal, in response to the user clicking your custom back button.

UIButton on left side of screen (in iOS 7 navigation slide area) not highlighted

I have a UIButton on the far left of a view controller (on a XIB), of say 100 points wide.
If the view controller is on a regular tab (i.e. not pushed on navigation stack) the button highlights as expected when tapped.
However, when the view controller is on a More-tab (so pushed on the navigation stack), the button is not highlighted when tapped on its left side (say the left most 50 points). The button does function, it's action is being called. But, when tapped on the right side it does highlight. (BTW, I think this is a general issue when the view controller is pushed from any other view controller; does probably not have to be More tab.)
After some research it turns out it's when I tap in the left screen area with which you can iOS-7-slide back to the parent view. Any ideas why this is, and how to make the button work properly again.
Thanks for your time!
I can confirm this bug with almost no code at all. All you need is an image file to serve as the background image. In the storyboard set this up:
Navigation Controller -> (root view controller) ViewController -> Button -> push segue... ->
ViewController2 -> Button
Put the second button up against the left side of its containing view (ViewController2's view) and set the image file as its highlighted background image.
Now run the app and tap the first button, to summon the second view controller's view. Tap the button at its right side: the highlighted background image appears. Now tap the button at its left side: the highlight background image does not appear, but the button is in fact receiving the tap (you can confirm that by giving it an action method that logs).
So, I would say you've got yourself a legitimate bug and you should report it to Apple. I'm certainly going to!
Unless you require the iOS 7 swipe-to-pop gesture, you can fix this bug by disabling that gesture recognizer:
self.navigationController.interactivePopGestureRecognizer.enabled = NO;

showing a box type-view on click of a button and on click of a tab bar item

In my application, i need to show a dilog-type view when a user clicks on a UIButton. I need to do the same thing when the user clicks on a tabBar item of a UITabBar
Sorry, in order to make myself clear, i had to create it in paint. Should i create a view with background image of the dilog box, and add two buttons in the view accordingly? I also need to give an alert-view like effect to the view when it is shown.
How do i implement it in a tabBarController?
On clicking on the red button, the view with black border should be shown with an alert-view type effect.

present view on part of screen; disable surrounding views but keep them visible

When the user presses a button, a text view should pop up in the middle of the screen. Two requirements:
1) Whatever was displayed before should still be visible (except where covered by the text view or keyboard).
2) If the user taps outside the text view or keyboard, nothing should happen.
I thought that if I presented the text view in its own VC, that would address #2, because I think that's how modal presentations work. However, when I do this, even though I set the background of the text view's VC to transparent and tried reducing the frame, all I get is the text view surrounding by black. Nothing is visible behind the presented VC.
EDIT:
It has come to my attention that apparently when you use a tab bar controller, that object does all of the presenting, no matter what VC actually sends the present message to itself. I am using a tab bar controller. Maybe this is part of the issue and forecloses the option of using presentViewController. So I need a different method!
You can just add a transparent view the size of the whole screen and put your textView in that. The transparent view won't allow touches to pass through. Then whenever the user is done entering text, you can just remove that transparent view (and the textView along with it) from its superview.

Resources