NavigationView back button not showing
OK - for any other poor soul who may encounter this...
When I found that even a trivial NavigationView had no 'Back' button (see question), it became clear that the trouble was not in the view code at all. Took some searching but discovered that somehow the default accent colors in the Assets file had been changed to white. This meant that the 'Back' button was white against a white background and was thus invisible.
Deleting these white accent colors causes SwiftUI to use defaults. Now the 'Back' button shows in blue as expected.
SwiftUI - How to remove white background behind List that is styled with SidebarListStyle, in portrait mode
Problem
Weirdly, if I add .navigationViewStyle(StackNavigationViewStyle()) to
the NavigationView, the white background disappears and it launches
fine.
This is because in iOS 14 the default styles of NavigationView
or List
are no longer always the same. See:
- SwiftUI iOS14 - NavigationView + List - Won't fill space
Solution
You can use a different NavigationStyle
depending on the @Environment(\.horizontalSizeClass)
:
struct CustomNavigationStyle: ViewModifier {
@Environment(\.horizontalSizeClass) var horizontalSizeClass
@ViewBuilder
func body(content: Content) -> some View {
if horizontalSizeClass == .compact {
content.navigationViewStyle(StackNavigationViewStyle())
} else {
content.navigationViewStyle(DoubleColumnNavigationViewStyle())
}
}
}
NavigationView {
...
}
.modifier(CustomNavigationStyle())
Status bar and navigation bar appear over my view's bounds in iOS 7
You can achieve this by implementing a new property called edgesForExtendedLayout
in iOS7 SDK. Please add the following code to achieve this,
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
You need to add the above in your -(void)viewDidLoad
method.
iOS 7 brings several changes to how you layout and customize the
appearance of your UI. The changes in view-controller layout, tint
color, and font affect all the UIKit objects in your app. In
addition, enhancements to gesture recognizer APIs give you finer
grained control over gesture interactions.Using View Controllers
In iOS 7, view controllers use full-screen layout. At the same time,
iOS 7 gives you more granular control over the way a view controller
lays out its views. In particular, the concept of full-screen layout
has been refined to let a view controller specify the layout of each
edge of its view.The
wantsFullScreenLayout
view controller property is deprecated in
iOS 7. If you currently specifywantsFullScreenLayout = NO
, the view
controller may display its content at an unexpected screen location
when it runs in iOS 7.To adjust how a view controller lays out its views,
UIViewController
provides the following properties:
- edgesForExtendedLayout
The
edgesForExtendedLayout
property uses theUIRectEdge
type,
which specifies each of a rectangle’s four edges, in addition to
specifying none and all. UseedgesForExtendedLayout
to specify which
edges of a view should be extended, regardless of bar translucency. By
default, the value of this property isUIRectEdgeAll
.
- extendedLayoutIncludesOpaqueBars
If your design uses opaque bars, refine
edgesForExtendedLayout
by
also setting theextendedLayoutIncludesOpaqueBars
property to
NO. (The default value ofextendedLayoutIncludesOpaqueBars
is NO.)
- automaticallyAdjustsScrollViewInsets
If you don’t want a scroll view’s content insets to be automatically
adjusted, setautomaticallyAdjustsScrollViewInsets
to NO. (The
default value ofautomaticallyAdjustsScrollViewInsets
is YES.)
- topLayoutGuide, bottomLayoutGuide
The
topLayoutGuide
andbottomLayoutGuide
properties indicate the
location of the top or bottom bar edges in a view controller’s view.
If bars should overlap the top or bottom of a view, you can use
Interface Builder to position the view relative to the bar by creating
constraints to the bottom oftopLayoutGuide
or to the top of
bottomLayoutGuide. (If no bars should overlap the view, the bottom of
topLayoutGuide
is the same as the top of the view and the top of
bottomLayoutGuide
is the same as the bottom of the view.) Both
properties are lazily created when requested.
Please refer, apple doc
Related Topics
Get the Value of Variable Out of Closure Swift
Changing Selectedimage on Uitabbaritem in Swift
How to Refresh a Timer in a Today Widget
Swift 4 Get Error Code from Error
How to Add Interactive Uilabels on Top of a Uiimageview
How to Calculate a Random Cgpoint Which Does Not Touch a Uiview
How to Access My Swift Classes from My UI Tests
Converting an Existing Project into Customizable Framework
Traverse View Controller Hierarchy in Swift
Swift, Google Map Fit Bound for All the Markers
Pausing Spritekit Game Using Appdelegate in iOS8
Locationmanager Didupdatelocations Fires Twice on Device, Only Once on Simulator
Convert Urlrequest to Nsmutableurlrequest
How to Store Array in Nsuserdefault in Swift