I would like to hide the header of my scrollview.
I have a scrollview
//Contains everything inside the view
let scrollView = UIScrollView()
scrollView.alwaysBounceVertical = true
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.showsHorizontalScrollIndicator = false
which spans across the whole width and height of my view. When scrolling down, a weird header appears and blocks a bit of the scroll view content. I would like to hide that overlay. The worst thing is, that in bright mode, the overlay is white. That clashes with my colors. How do I go about removing it?
The overlay is the navigation bar - it appears as soon as you scroll. To hide it completely, you can set navigationController?.setNavigationBarHidden(true, animated: false). Or, you can pass in a transparent appearance for navigationController?.navigationBar.standardAppearance.
Related
I have a UIScrollView that is constraint to view.topAnchor, so it scrolls up to the top edge of an iPhoneX. However, when I add content to the scrollView (such as a UIImage), and constraint it scrollView.topAnchor the content is inset to the safeAreaLayoutGuide. This seems to happen with scrollViews since if I take the content out and place it in the view, it also moves to the screen edge.
Anyone have any ideas how to fix this?
Try setting the view controller's automaticallyAdjustsScrollViewInsets to false in viewDidLoad (self.automaticallyAdjustsScrollViewInsets = false). From the documentation:
The default value of this property is true, which lets container view controllers
know that they should adjust the scroll view insets of this view controller’s
view to account for screen areas consumed by a status bar, search bar, navigation
bar, toolbar, or tab bar. Set this property to false if your view controller
implementation manages its own scroll view inset adjustments.
UPDATE:
As was mentioned, automaticallyAdjustsScrollViewInsets is deprecated in iOS 11+. You can do a version check and to fix it for older versions of iOS as well. Example:
if #available(iOS 11.0, *) {
scrollView.contentInsetAdjustmentBehavior = .never
} else {
self.automaticallyAdjustsScrollViewInsets = false
}
I am new to Swift, and I am struggling to find a solution: in my UITableViewController, I want to make a Toolbar that I have added to the storyboard fixed or "sticky" to the bottom of the view at all times.
Currently, after dragging a toolbar into the UITableViewController, it does add this toolbar; however, it places the toolbar as the final row of the table.
I want this toolbar to sit above the navigation tab bar at all times, making it fixed or sticky.
I have tried changing the View's content mode (by setting it to Bottom in the Storyboard) but it does not make a change in the UI.
Is there a way to set this programmatically to always show at the bottom and let the table scroll above it?
//create a tool bar and add it in view
let toolbar = UIToolbar()
toolbar.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(toolbar)
Set constraints to toolbar...
//top constraint to toolbar with tableview
self.toolbar.topAnchor.constraint(equalTo: tableview.bottomAnchor).isActive = true
//bottom constraint to toolbar with super view
self.view.bottomAnchor.constraint(equalTo: toolbar.bottomAnchor).isActive = true
//leading constraint to toolbar with super view
self.view.leadingAnchor.constraint(equalTo: toolbar.leadingAnchor).isActive = true
//trailing constraint with toolbar with super view
self.view.trailingAnchor.constraint(equalTo: toolbar.trailingAnchor).isActive = true
I want to show vertical indicator of UIScrollView when user move to controller and not start scrolling. Like in UITableView when user move to tableView vertical indicator shows automatically even if the user not start scrolling. How to do it?
You can use the function flashScrollIndicators.
Documentation:
Displays the scroll indicators for a short time. This should be done whenever you bring the scroll view to front.
Use This Code:
self.ScrollView.showsVerticalScrollIndicator = true
Make sure you have set UIScrollViewDelegate correctly,
self.ScrollView.delegate = self
You can enable and disable it from storyboard interface.
Vertical checkbox handles vertical scroll indicator
Horizontal checkbox handles horizontal scroll indicator
The same can be set programatically like
// For vertical scroll indicator
scrollView.showsVerticalScrollIndicator = true
// For horizontal scroll indicator
scrollView.showsHorizontalScrollIndicator = true
Try to use scrollView.flashScrollIndicators()
I'm building an application for iOS, which is using a navigation controller. I want to put a view in the titleView, and have it fill the whole width of the navigation bar.
I'm calling setupNavBar in viewDidLoad of the view controller that is embedded in the navigation controller. Here is how I do:
func setupNavBar() {
let navBar = navigationController?.navigationBar
// navBar!.translatesAutoresizingMaskIntoConstraints = false
// navBar!.frame.size.height = CGFloat(100)
let searchBar = UIView(frame: navBar!.frame)
searchBar.bounds = CGRectMake(0, 0, navBar!.frame.width, navBar!.frame.height)
searchBar.backgroundColor = UIColor.brownColor()
navigationItem.titleView = searchBar
}
But the view (brown - "searchBar"), doesn't cover the full navigation bar:
So I figured out that the problem was related to Autoresizing and Constraints, because if I call navBar!.translatesAutoresizingMaskIntoConstraints = false, I can freely set the sizes of views frame, so there must be some constraints that change the view's bounds. But I would like to keep as much of the autolayout behaviour as possible.
Is there a way to only change the contraints on the titleView?
I'm doing everything programmatically, I don't use the storyboard or xib's!
EDIT:
But it doesn't seem like there is any constraints on either navigationItem or navBar:
for someObject in navigationItem.titleView!.constraints {
print(someObject)
}
It doesn't print any constraints. neither if I use navBar.constraints!
EDIT 2:
I have a screenshot from "View UI Hierarchy" from the debug navigator:
It seems that the view(brown) alligns with the Navigation Bar Back Indicator View, maybe this is a clue to what causes the problem?
How come the view is resized?
Two different suggestions here:
1. You can try the
navigationItem.titleView.sizeToFit()
Otherwise you could set the background colour of the navbar to brown as it appears you wish the brown bar to cover the entire width of the navbar. If you want to add other views on top of that you then can.
You could also try to make an outlet to the title view and add an NSLayoutConstraint using
navigationItem.titleView.addConstraint(NSLayoutConstraint: NSLayoutConstraint)
I am not entirely sure whether that will work, however.
I view imbedded in a Navigation Controller which is slightly transparent. This view contains a UIscrollview. This UIScrollview has the following subviews: UIImageView, UILabel, and UIWebview. All these other views are working correctly. When the view loads, everything is in the correct position (The views are below the Navigation Bar). However, as soon as the screen is tapped, the scrollview repositions itself to the top of the view (aka behind the Navigation Bar, which is at the top, and I can see that this is true because the Nav Bar is slightly transparent)
Any idea why this is happening? I set up the scrollview like this:
self.scrollView.frame = CGRectMake(0, self.navigationController.navigationBar.frame.size.height, self.view.window.frame.size.width, self.view.window.frame.size.height);
Also set these properties:
self.scrollView.scrollEnabled = YES;
self.scrollView.alwaysBounceVertical = YES;
self.scrollView.bounces = YES;
Anybody know why this is happening?
I'd similar problem, but only on iOS 7.0. Try to set the translucent = NO property of the navigationBar. This will make the navigationBar opaque. Although if you want the navigationBar to be transparent, try to change the contentInset of the scrollView to adjust the content as you want. Hope that this will help :)