UIButton in custom UITableViewCell not registering tap - iphone

I have a custom UITableView, with custom UITableViewCells that are dynamic in height. I create the skeleton of the custom cell in storyboard, which includes (for simplicity) just a label at the top (static height), a label in the middle (dynamic height), and a label at the bottom (static height).
I have a tap gesture setup on the bottom label.
The problem I am having, is the tap gesture on the bottom label does not work (all the time). It seems to work when the middle label is shorter (2 lines), than when it is longer (2+ lines). If I move the label to the top, and anchor it to the top of the superview, the tap event gets registered every single time.
Has anyone else experienced this, and perhaps has a solution to this problem?
It seems to work fine if I add the label programatically.

Are you sure your bottom label is not occluded by the label in the middle? Labels have default transparent background, maybe your bottom label is visible but not accessible for tap gestures. Try downsizing your middle label or add tap gesture compatibility to middle label also so that you understand if it takes away the tap gesture from the bottom label. If this is case you can fix it by bringing bottom label to front
[tableCellView bringSubviewToFront:bottomLabel];

Related

Center Label vertically between two UIButton's

everybody some I'm having some trouble vertically centering the or label between the Sign in with apple button and also the login button. Keep in mind that I am creating the SIWA button programmatically and setting the constraints that way also. I have tried getting the origin y coordinate for both buttons, dividing them by 2 and then setting the vertical constraint from the login button to the or label to be (loginButton.frame.origin.y - (divided by 2 value)) but that doesn't seem to work. Thanks for your help.
There's a couple ways to solve this:
Put the 2 buttons and the label in a vertical UIStackview with distribution set to equal spacing. Stackviews are very flexible too, especially in more complex layouts.
Create an empty UIView that sits between the two buttons, then add the label as a subview and center it. Alternatively, you can create 2 spacer views with equal height constraints above and below the label:
V:|[Button][space][Label][spacer2(==spacer1)][Button2]|
Very easy approach: by default, UILabel centers its text vertically in its frame.
So,
constrain the Top of the Label to the Bottom of the top button
constrain the Bottom of the Label to the Top of the bottom button
All done :)

How to use a scrollview containing buttons with auto layout

I need some help figuring this out.
I have a simple UI I need to implement. I have 4 buttons that take up the entire screen and with the scrollview, I want the user to be able to scroll to make the 5th button visible. I know how to use auto layout to make my first four buttons display how I want them. The first button is 40% of the visible screen, the second button is 15%, the third 30% and the last button is 15% of the visible screen. The 5th button should be hidden but then revealed when the user scrolls down.
(To clarify, all buttons have width equal to their superview, proportional height to the superview and all buttons have no spacing between each other)
This is where I am stuck. I want the proportions as I stated above, but also want the 5th button to show when scrolled to, possibly at 10% of the now visible screen (with the first button now not showing itself fully). Is there a way to do this?
You can set the contentSize of the UIScrollView to be larger than the visible screen. The buttons can be sized and placed in a way to have all 5 buttons visible (with the 5th button actually off screen). The scrollView will bring the 5th button into view when scrolling.
I worked up a simple prototype using just a storyboard (and setting the contentSize of the scrollview in Runtime Attributes section, but this could be done in code if you need to pragmatically determine the button sizes.

Moving a label without having it nest under a screen filling UIView

I have a UIView implementing a GMSMapView which stretches to fill out the screen. I want a little label displaying text on top of this map on the top-right corner.
I managed to re-order the arrangement to successfully display it on top of the map while in the center:
But the moment I try to move it to another spot, it nests under Map Label and no longer shows up:
How can I prevent it nesting under the Map Label view?
First remove all constrains from the label, and then center the label in the middle of the View aligned perfectly. Then go to Resolve Auto Layout Issues and click Update Constrains after add Missing Constrains and run the app. Another way that I use stack the label and place in the middle and add the appropriate constrains. To add a Stack View select your label and click on the first icons horizontally placed on the PIN row.

iPhone - UITableviewcell label movement when press Editing

In the normal behavior when Edit is pressed, the red delete circles appear from the left. This shifts the entire cell to the left.
When this happens, custom labels on the far right of the cell overlap the cell movement touch area.
The solution is to move custom UILabels to the left when edit is pressed.
How is this done?
Assuming your UILabel is being added to the contentView of your cell, just make sure your subviews (whether a UILabel or other UIView-derived object) have their autoresizingMask set up to allow flexible width (UIViewAutoresizingFlexibleWidth). Also, your left subviews need UIViewAutoresizingFlexibleRightMargin, while your right subviews should have UIViewAutoresizingFlexibleLeftMargin.

Covering space from one UITableView's cell with another one

The design of the UITableView is something like this:
I want to make my cells with a tiny triangle, like in a comic book. The thing is, how can i add the triangle to the size of my custom cell? The common rectangle size wouldn't work if i want the user to be able to tap that little rectangle.
And how can i make the opposite? I want the triangle to cover the space of another cell, so tapping the little triangle of the first cell, covering part of the second cell's rectangle space, would activate de first one. This is, substracting a little triangle from the cell's space.
Not sure it would work, but building on user697562's comment, you could try the following:
Add a small UIView to the table cell to represent the small triangle
Rotate it using its transform property, making sure that, along with its frame, it will have the proper placement.
Add a UITapGestureRecognizer to the UIView
Add an instance variable to the view to save the indexPath of the cell it's in (or even the above cell, since it will be associated with the above cell). This way when the gesture recognizer is triggered, you know what row you're in.
Write the action method associated with the gesture recognizer to do the same thing as tableView:didSelectRowAtIndexPath: would do for the above cell.
Set the separatorStyle property of the UITableView to UISeparatorStyleNone, so that it won't draw the lines between cells. If this doesn't work just set the separatorColor property to your table cell's background color.
Draw a border along the top & bottom of the cell, accounting for the triangle.
Good luck with it! Let me know whether it works if you try it.