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

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.

Related

UIStackView as a root view of a XIB

I'd like to create a small UIViewController that contains an UITextField and a UILabel going one after the other.
I've decided to use an instance of UIStackView to lay out the subviews.
However, I have to add a UIStackView as a subview of the parent UIView in XIB.
Is it possible to configure XIB the way that the root view of the controller would be of a certain class, eliminating the need for the extra view?
I've attached the current view hierarchy. I'd like to get rid completely off the topmost View.
Yes you can, you need just to set the stackview as the the root view of your view controller as following:
you can do the following:
1- create new file -> under the user interface choose "Empty"
2- then you will get an empty XIB
3- after that you can add your UIStackView from the UI Component picker
4- put your UITextField and UILabel
5- finally create your .swift file and wire it up with your XIB

How do I add a footer to a UITableView using Storyboard?

Same as this question, only the proposed solution doesn't work for me. When I drag a view to the bottom area of a tableView, it tries to add it to the list of cells higher up:
I'm sure I'm missing something simple... I'm new to storyboards.
EDIT:
Maybe it is adding a "footer" (though, it doesn't label it as such), it's just not adding it low enough. I was ultimately hoping to add an item that would appear at the bottom of the screen (and stick to the bottom of the screen).
TIP: You can use the Tree view (outline view) on the left to arrange the Views (and sub views). I have done a lot of storyboard editing, and dropping things into table views rarely go to the correct hierarchy level in the tree view.
Create a New UIViewController
Insert a UITableView
Resize the tableview by dragging its dimensions
The attached picture has a UITableView on TOP of a UIViewController's UIView. Make sure that you set the delegates in the UIViewController's .m, assign the tableView as a property of the view controller, and then set the tableview's delegate property to the UIViewController object. i.e.: tableView.delegate = self or [tableView setDelegate:self]; also with datasource.
OR you can just click the tableView, on story board, and then drag its delegate and datasource property to THE UIVIEWCONTROLLER! not the view! You can do this by dragging it to the this highlighted part of the view controller's toolbar on the storyboard:
Either you can create a footer view programatically or you can load a view from UIView outlet
UIView *tempFooter=[[UIView alloc]initWithFrame:self.Footerview.frame];
[tempFooter addSubview:self.Footerview];
self.ItemDetailsTable.tableFooterView=tempFooter;
self.Footerview //View outlet
You need to set all the needed constraints of the self.Footerview to get the required layout of the footer view.But you don't need to set constraints for tableview footer itself.

Add UIScrollView to UIViewController

I am trying to add a UIScrollView to an existing UIViewController (with navigation and tab bar) using storyboard and autolayout but I don't get this to work. Up to now I have added all components to the controller by dragging them on it. Now I try to group them in a UIView, so that I can make this UIView a subview of UIScrollView. When I drag my existing components as a subview of my newly created UIView the position of it is wrong. So I must manually correct all positions. Afterwards the compoents are 64px below their old position.
I just cant get it to work. Is there a tutorial or something how to add an UIScrollView to an existing storyboard?
This is the easiest way to learn how to control a UIScrollViewer within a Storyboard.
http://agilewarrior.wordpress.com/2012/05/18/uiscrollview-examples/
You might want to deselect Ajust Scroll View Insets in interface builder.
You can also set in your viewDidLoad :
self.automaticallyAdjustsScrollViewInsets = NO;

Objective-c ViewControllers and Views

I know this has been talked about ad nauseam on here but I'd like to get some perspective from other developers:
If I have a view controller with a view and then I add subviews to that view, does each subview need its' own viewcontroller or can the first viewcontroller also control the subviews?
So
UIViewController
UIView
UIView
UIButton
UILabel
UIView
...
the subviews do not take up the whole screen - they are for the most part the width of the screen but maybe 200.0f tall or less. They display information for a sales tool app.
The rule of thumb I was presented when I first started iOS development was if the view took up the whole screen, then it required its own viewcontroller, if not make it the subview of a viewcontrollers.view
Just wondering what the accepted approach is.
The View controller can access the views that are created in XIB, just create IBOutlet properties for the views in view controller source files and link the views to file's owner in interface builder.
Your rule of thumb is correct.

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