How do you display an image when the user touches it and is hidden again when they are not longer touching it? - objective-c

I am creating an application and I am having trouble finding any information on how the attribute for the image is only displayed when the user hovers over the textbox and is hidden again when the user is no longer touching it.

There are several ways of doing this. I'll give one possibility:
You can use a button and add 2 actions, one for
UIControlEventTouchDown
and one for
UIControlEventTouchUpInside | UIControlEventTouchUpOutside
in the first one you show the image and in the second one you hide the image

Related

Dynamically create views containing buttons - what about constraints?

I want a menu (hidden on the left side of my app) with a variable amount of buttons (depending on the user). I took the app over from another developer and he manually added every view and every button and it is a pain to maintain if you want to add another button in between or change something. So I want to redo it automatically.
But how can I achieve that? Let's say i have on the left x views, each containing an image, a button and a separator (to the button below). So I basically only create one single prototype view, button combo and reuse it for all other buttons. But how do I arrange them so the constraints are correctly set?
I would go with a table-view. Setup a cell with an image and a button, separators come for free in a table-view. Make sure the cell has a delegate for the button call-back or a closure to handle the button tap.
Add a controller/manager to control the number of views based on the user.

Adding A View To An Existing View Programatically

How can you add or replace a view within a view with code? I'm programming for OSX, not IOS.
I am using a drawer that utilizes a custom view. In the custom view I have two boxes, one with a custom set of icons that I want to stay static and another box that has the information related to that button. What I want to do is when a user clicks one of the buttons that the 2nd box view changes to reflect the info for that button.
For example, I have five buttons and the default 2nd box is "Info", if the user clicks the 2nd button in the first box view I want to change the 2nd box to be the "List" box instead while the 1st box with the buttons stays intact.
I'm not sure how this would impact constraints since while the first box is a fixed size, the 2nd box needs to be dynamic so that it fills in the "rest of the space" so that when the drawer size changes with the window size that the 2nd box is taking up the remaining real estate.
Thank you!
I have implemented such a scenario in the past using a tabless NSTabView, and an NSSegmentedControl (for the buttons). The NSTabView has it's -takeSelectedTabViewItemFromSender: action connected to the NSSegmentedControl, using Interface Builder.
In the Connections Inspector, this shows up like so:
This has the effect that the index of the selected NSTabViewItem in your NSTabView will correspond to the index of the selected segment in the NSSegmentedControl.

UIText field does not respond to touch after switching view

In my app, I have a text field that works fine, however after going back to the main menu and then back onto the page with the text field, the text field becomes un-touchable, the keyboard does not show no matter how many times you click it.
Here is a screen shot of the interface http://tinypic.com/view.php?pic=y11sm&s=6
I think I may have to add code or connect an action with the text field, but how?
Thanks for your time.
You can remove subviews that you don't use anymore like #Kim has already told you or if you need these subviews but they are blocking the action, you can bring your textfield to front using,
[your_view bringSubviewToFront: your_textfield];

How do I properly move a scrollview when assigning a first responder?

I have a form in a UIView which consist of multiple textfields, couple of textviews and two fields that are interacted with by the means of an invisible button overlaid on them. When you click on a textfield, the keyboard pops up for text entry and I added a toolbar on it for navigating to the previous and next data entry (whatever the data entry is, be it a textfield, textview or one of the two special cases that are interacted with a button). Now, when I navigate with between textfields with those buttons everything works fine. My scrollview's content moves along the element that becomes the firstresponder (with the help of a piece of code from stackoverflow that scrolls the view while taking into account the height of the keyboard that hides a good portion of it). Here is a visual example.
The problem arises when I want to switch out of a specific data entry (date) that interacts with a hidden button. I'll give some context first. Those data entries show datepickers (one for the date, another for the time) in action sheets, and those action sheets also have navigating button in a toolbar, like so.
The code from stackoverflow that readjust the view do so in the didBeginEditing delegate methods of the textfields and textviews, so when I assign them first responder the scrollview adjust itself while taking into account the keyboard.
This means that, in the case that I switch into a special data entry, I manually move the scrollview's content so I can view the next element. When I switch from a special entry into a textfield I assume that the previously mentioned code from stackoverflow kicks in and adjust the view. It actually does when I move from the hour data entry (which uses a datepicker in an actionsheet) into the next element which is a textfield. However, when I'm at the date data entry (which is directly before the hour data entry) and press previous to assign the first responder to the textfield above it, the scrollview goes way ahead the text field, like so.
What's important to note is that this problem only occurs when the textfield is not in view. This makes me suspect that I'm incorrectly using the code that readjust the view. For instance, there is a constant in the code that represents the height of the keyboard. I tried changing it from 216 to 260 (so it takes into account my toolbar added on top of the keyboard) but this results in strange black artifacts near the buttom that only occasionally appears.
I'm kind of lost in this bug, and my post is already pretty long. I've prepared an example of my problem in a new project, if any of you could take a look into it I'd be very appreciative.
Here it is

Custom UI segmented control

I'm wondering if in IOS is possible to customize segmented control like the attached image. I have tried to change buttons image, but the segmented control container is still visible under the customized buttons. I observed that the segmented buttons title disappears if you add button image. Custom button images must include title?
Many thanks
Just roll your own. Make three UIButtons with two images for each state and write logic to allow only one of them to be selected.