As shown on the image, I have ContentViewController, PageViewController and WelcomeController. And you can see, that I have buttons on my WelcomeController, in the bottom.
With the code: http://pastebin.com/Kf70RQWM
I put PageView with the ContentView into my WelcomeController, but it covers whole my screen. I did try using this:
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.size.height - 50)
to have 50px space for my buttons, but in that case I get the next:
black background instead of my buttons.
Question: how can I put my buttons to those black space?
You forgot to setup autolayout. Please check the pull request here, https://github.com/orkhanalizade/messenger/pull/1.
Related
I want to create UINavigationBar with rounded corner. It will look like this
What I am thinking is I add UIView with rounded corner and insert it in navigation bar. So this is my code
let roundView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 44))
roundView.backgroundColor = UIColor.whiteBackground
roundView.roundCorners(corners: [.topLeft, .topRight], radius: 20)
navigationController?.navigationBar.insertSubview(roundView, at: 0)
setTitleTextColor(color: UIColor.black)
By the UI, this works well. But then my UIBarButtonItem is missing, it covered up by my custom view and couldn't be clicked. So my question is, how to add subview in navigation bar?
Thank you!
Just not use UINavigation bar and create all by scratch. Is the easiest way. Otherwise you can try with pattern image:
navigationController?.navigationBar.backgroundColor = UIColor(patternImage: UIImage(named: "background.png"))
From Storyboard,
You have ViewController with navigationController
Select navigationController and deselect the below selected option i.e. Show Navigation Bar visibility.
Take a UIView (purpleView) with constraints
top, leading trailing = 0 w.r.t. superview
height = 64
Take another UIView (whiteView) in purpleView with constraints
top= 20 (for status bar)
leading trailing bottom= 0 w.r.t. purpleView
Now add cancel and label to your whiteview
Now your UI Hierarchy is like below
Take outlet of whiteView and make corner radius
Thats it.
If you'r not using storyboard then you can do same with code also. In this case you have to set frame of purpleView and whiteView instead of constraints.
Hope now its clear to you.
How about to make it as a normal UIView and hide the navBar and show it in the next VC, who will know which trick you have used.
read this short article here
I want to have the Tab Bar at the top of the screen. One post suggested to do the followings (I put the following code in the viewDidLoad() of the UITabBarController) :
CODE
let tabBar = self.tabBar
// yStatusBar indicates the height of the status bar
let yStatusBar = UIApplication.sharedApplication().statusBarFrame.size.height
// Set the size and the position in the screen of the tab bar
tabBar.frame = CGRectMake(0, yStatusBar, tabBar.frame.size.width, tabBar.frame.size.height)
There are 2 problems with this solution:
The bottom of the screen is left with a black region where the tab bar was
The Tab bar covers the view at the top of the screen - the constraints of that view is relative to the device but they should be relative to the Tab bar. However when the screen is designed in the IB there is no Tab bar to relate to.
Is there a way to overcome these problems? P.S. I am new to IOS
let tabBar = self.tabBarController?.tabBar
// Set the size and the position in the screen of the tab bar
tabBar?.frame = CGRect(x: 0, y: self.view.frame.height, width: (tabBar?.frame.size.width)!, height: (tabBar?.frame.size.height)!)
Although it is against the human interface guidelines there exist a hack if you really want to.
You could create a blank UIView in your storyboard (with proper constraints set up) that would essentially be the placeholder for the tabBar when loaded.
You then set top constraints for your other views relative to this view that you have setup.
This works, but probably not best practice to do so
Having a bit of an issue with my tab bar app. I want to hide the bottom bar in the next controller I push to. I have set the hidesBottomBarWhenPushed to true in the IB. I have a UILabel pinned to the bottom of the screen in this controller. When I push to it the label is not at the bottom of the screen but above it at the same height the toolbar was. Any ideas what I might be doing wrong here? Any pointers would be great!
Not the cleanest of solutions, but you could rearrange the label when the BottomBar gets hidden
Like this:
label.frame = CGRect(x: label.frame.origin.x, y: label.frame.origin.y + 'tabbarHeight', width: label.frame.width, height: label.frame.height)
You would just have to add the height of your tabBar to the y value
Edit: This is also reversible, so when you are navigating back, just subtract the tabBarHeight from the y value
How you can see my imageView doesn't cover full screen. How can I do that my imageView will cover full screen and dots was on imageView?
I did it with viewController + PageViewController.
I resize it with:
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.size.height)
My code is long, so if you want to see exact part of my code - just ask about it
If you have to show only images in your array, then you can use UIScrollView to contain all images.
After that you can use UIPageControl. Add UIPageControl to your UIView.
Then in ScrollViewDidEndDecelerating method, by computing contentOffset of UIScrollView you can set UIPageControl.
Hope this helps.
You can use the pageVC delegate to know when the page was changed and update the dots.
I noticed that with a NavigationController on an iPhone, the height is 460. So it includes the whole screen except the status bar.
However, when I add something at coordinate 0, it shows up after the NavigationBar, although the size of the navigation bar is included in the height (meaning the entire frame of this view sticks off the screen).
Did I make a mistake? If not, why is it structured this way?
NSLog(#"Frame: %#", [NSValue valueWithCGRect: self.view.frame]); // prints {(0, 20), (320, 460)}
UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(0, self.navigationController.navigationBar.frame.size.height, self.view.frame.width, 50)];
[self.view addSubview: scrollView]; // showing up 44px *after* the nav bar
I already answered your other similar question, but here is one for this.
In viewDidLoad you will see the views height as 460 because at that point it hasn't resized to account for the Nav Bar.
But If you printed the same frame out in say viewWillAppear you will see that now the frames height has adjusted for the Nav Bar.
So if you want to add something in viewDidLoad, you need to add it based on the views frame, add whichever resizing mask will do the job you want, and see it adjust correctly once the view appears.