How do I make a UIView clickable in MonoTouch? - uiview

I'm currently trying to create a simple UIView which contains some labels and images.
How can I set the UIView as clickable?
I have already tried to override the onTouchEnded method, but when I added the labels and the images as sub-views to the view, the method is no longer called.

but when I added the labels and the images as subviews to the view the method is not called anymore.
Because UIImageView and UILabel have their userInteractionEnabled property set to NO by default. Set it to YES (true) and that should be fine.

Related

How to make custom UIView properties disappear as soon as they exit the boundaries of the view?

I have a custom UIView that has a few properties like UIButtons and UITextFields. I am animating these to go left and right using UIView.animate(withDuration: 0.25) {} and am simply changing the constraints in the closure to move the properties to their respective positions. These positions are often outside of the view, because I want them to disappear. Is there someway that I can keep the animations, but once the properties begin cross the boundary of the custom UIView, they disappear instead of showing up outside the UIView?
It would be clearer if you called them subviews.
Anyway, based on your comment, it sounds like you want to set the superview's clipsToBounds to true. Then any portion of a subview that is outside it's superview's bounds will not be visible.
You can set clipsToBounds programmatically, or in the view's Attributes inspector in your xib or storyboard.

Can I create a custom UIView from a .xib and then use that view for my UIButton?

I need to refactor my UI where I had a UIButton with two labels placed on top of it and constraints set in order to display it properly.
What I have done is created a custom UIView that looks exactly like my previous button but now with the labels contained within the view and constraints inside the .xib instead of in the storyboard where they were placed.
I want this new view to be used as the buttons view; is this possible?
If not, is the way to make my custom view "like" a button is to used touchesBegan/touchesEnded? How do I handle the touchDown highlight of the system UIButton?
Thanks!

How to resize custom (created in separate file) UIView height on the ViewController which uses it?

I have a custom UIView (consisting of .swift and .xib files). There is a button inside of it which changes its height.
I'm using this custom UIView some of my ViewController. To do it I drag UIView on the ViewController and set its class to my custom UIView. This also allows me to use this button and "change" displayed size of my custom UIView.
However the size of UIView which contains my custom UIView doesn't change and I cannot use GMSMapView which lies under this view.
How can I solve this issue and change actual height of this view in the ViewController too?
The easiest way is to create an outlet of a constraint from storyboard and adjust its constant-property. That will course the view to resize.
Its an unusual behavior that a view resizes itself. The SuperView or ViewController should manage things like that.
When creating an outlet of the constraint, you should consider creating the outlet within the ViewController and not within the view.

Custom Prototype Cell designed in Storyboard with Custom View Controller

The main problem is that it does not respect the design done in the storyboard. The coordinates of the image and the labels are as a basic cell. Note that such attributes are observed as the alignment of the label.
The button that has been added, is below the label.
I've definitely seen this issue before and I believe it is because imageView and textLabel are properties of UITableViewCell and the default implementation of layoutSubviews is overriding your storyboard's layout with UITableViewCell's defaults.
Try overriding layoutSubviews, or provide your own image and label properties (named differently from UITableViewCell's, ie: myImageView and myTextLabel).

UIView not appearing on xib

I am trying to make a UIView appear as a rounded box on terms and conditions screen as seen here
When I add an UIView to the xib IB the UIView doesn't show up. But if I add a UIButton to the view then I see the view. How can I make the UIView always visible to a specified frame size?
The problem was that I didn't connect the view to the controller.

Resources