I'm new in the swift/iOS application development, I'm currently working on an app for which I need to create the layout programmatically. My app contains a navigation bar at the top and a UIView object, where I'm rendering the controls. The issue I have is that I'm not exactly sure of the height of the navigation bar, so when rendering some controls are currently bellow the navigation bar, and the user cannot see them.
I could easily set a hard-coded height, but then it doesn't work properly across devices.
My best scenario really would be to get the position of the UIView object and place all I need within those boundaries, or to tell my object (e.g. UILabel) to position relative to the UIView.
Thanks for your help!
You can get the frame of the navigation bar from your UIViewController, which is itself a UIView subclass, thusly:
CGRect navigationFrame = self.navigationController.navigationBar.frame;
Related
I have a viewcontroller. On my storyboard I have dragged a TextField onto it.
In my code, I define a rect, that needs to be positioned relative to the text field, as follows:
CGRect autocompleteRect = CGRectMake(schoolField.frame.origin.x, schoolField.frame.origin.y + 70, schoolField.frame.size.width,autocompleteTableView.contentSize.height);
That works fine, until I embed my TextField in a UIView.
The UIView itself is managed by auto layout to be positioned in the center of the Controllers .view.
I would say, that this should not be of any influence to the relative postion of my rect. However, it is:
Since the embedding of the TextField in a UIView, my rect is positioned differently, also depending on the screen size of the device I'm running it on.
So, I guess it's got something to do with AutoLayout,but I wouldn't know what I should tell my app to behave the way I want it to.
Thanks for your insights.
autocompleteRect is a rect inside CredentialsContainer, but you use it for a view which has been contained by UIViewController's view. That's why your autocompleteRect has wrong position when you use.
To solve issue, you need to add the view which will use autocompleteRect to CredentialsContainer.
Hope this can make you more clearly.
When I run my web app WebView takes over the status bar, as in the picture:
http://imgur.com/JggYPP2
I'd like to be separated.
An example is this:
http://imgur.com/Zll2Oes
How can I set the WebView to have this effect ?
Sorry for the links , but I can’t upload pictures because I'm new
Both UIWebView and WKWebView classes inherit from UIView, which means we can boil down the problem as a UIStatusBar instance incorrectly overlapping a UIView instance.
If you are using Auto Layout in a Storyboard, create a constraint (with a value of 0) between the top of the Web View and the bottom of the UIViewController view's Top Layout Guide. By relating your constraint to the Top Layout Guide, your Web View will always respond to the status bar height should iOS designers ever change it.
If you are rendering the Web View programmatically and do not wish to you use Auto Layout, check into CGRectOffset and CGRectInset to manually set the frame of your Web View. At the time of this post, the status bar has a height of 20 points.
UPDATE 12/1/17
Preceding the introduction of the first iPhone with a non-rectangular screen (the iPhone X), Apple introduced Safe Areas in iOS 11 to manage a UIView's relationships with the boundaries of a device. In addition to managing physical boundaries of the device, the Safe Area observes software boundaries such as a virtual home button.
Unless your app requires custom drawing, I recommend relying solely on Autolayout going forward. Within a UIViewController, relate your subview's topAnchor to the UIViewController view's safeLayoutGuide.topAnchor, and so on.
What I'm trying to do is very simple...i think. I want to make sure all the subviews within a view in my view controller are scaled to fit. Inside it.
My view controller has a menuview (subclass of uiview). Within that there are uiimage views, labels, and a button. The MenuView class I created has a nib file with a uiimage view that I want to scale to the size of the menuview depending on the device used. I'm not sure if the menuview is not staying constrained to the screen or if the uiiimage isn't, but when i run my program the menu runs off the screen.
Question:
- Can I force this (uiview and/or uiimageview) to stay on the screen using storyboard (programmatically is ok, but would prefer to try with storyboard)?
If anyone can point me to a good introduction to auto layout view and understanding the mainstoryboard that'd also be appreciate because it's insanely frustrating.
Screenshot: in the image below you can see I have a letter image that I want within the limits of the screen.
I am fairly new to UI elements in iOS (all of my apps were Gl games) but I'm trying it out and I found myself in a bit of a pickle...
The view controller for the bulk of my app is a subclass of UITabBarController and I have a few tabs with (currently empty) child view controllers. For the most part I have these working fine, but my problem is with correctly sizing and placing items inside of a tabbed view controller. If, for instance, I try to place something just above the tab bar, then I can't just set the Y position to the height of the the child view controller's view minus the height of the object I'm placing. I also need to account for the tab bar itself.
I can see that part of my problem is that I'm simply creating the view controller and not telling it what size it's view needs to be. Is there a function provided to me to calculate the height the view needs to be? I could just figure out the height of the bar and subtract that from the overall height, but that just feels to flimsy to me.
Any ideas?
EDIT:
I am doing it all programmatically and I don't intend to use Interface Builder. My main concern with the view size is making sure that things like table views fit snugly.
If you are using Interface Builder and auto layout, you can place UIView items on your UIViewController and if you set a size constraint on the view you're placing you can also set position constraints that are relative to screen edge or adjacent views, in your case UITabBar.
I want to create a footer fixed to the bottom of the viewport in an iOS app I'm developing (it's my first one, I come from a web dev background). However I'm having difficulty finding information on how to go about this.
What I have in mind is essentially just 3 rectangular buttons next to each other that are just constantly fixed to the bottom of the viewport. I tried dragging a toolbar into my scene as a starting point, but in the interface builder it's placing itself under my table cell, rather than fixing to the bottom. I feel like this is probably easier to do programmatically, but I just don't know where to start.
If someone could at the very least guide me in the right direction I'd really appreciate it. Thank you.
Okay... create/add custom UIView on your main view (self.view)
and set this custom view's frame = (0, 0, 320 , self.view.frame.size.height - 50) /// change value 50 to as per your requirement.
and add all of then UIControls such like textField, tableVie, button ...etc.. on this custom view.
Don't use a UITableViewController. Use a UIViewController, then add a table view and a toolbar. You'll need to implement the UITableViewDelegate protocol in code and then connect the delegate in interface builder.