xcode 9 iOS 11 navigationBar with title and segmented control - navigationbar

I have been using a UIView in my navigationBar as the titleView up to Xcode 8 iOS 10. The view was added in storyboard. In that UIView I have a label representing the title and underneath it a segmented control. This has worked fine up until iOS 11. Now I can no longer interact with the segmented control and the positioning is shifting up so that the title and half of the segmented control is off screen. I was using an empty space for the prompt field of the navigationBar to get the extra height.
Is there a way of adding a title and segmentedControl underneath it to a navigationBar without creating a custom navigationBar? I don't want to create a custom navigationBar because I want to keep the translucency properties of the default navigationBar.
At the moment here is what I see after running Xcode 9 iOS 11:

Add in Appdelegate.m
if ([UIScreen mainScreen].bounds.size.height >= 812)
{
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0,40,self.window.frame.size.width,self.window.frame.size.height-20);
}

Best way to manage this is to add the segmentedControl directly in the navigationTitle area in the storyboard and afterwards add a title in the inspector title textfield in storyboard when navigationBar is selected. This will show both the title in large font and the storyboard above it exactly like the missed calls page of iOS

Related

Xamarin.Forms ScrollView ScrollToAsync behaviour

I have been having issues with using the ScrollToAsync function of a ScrollView when running on Android, not tested on iOS yet.
I'm using Xamarin.Forms version 2.5.1.444934 using .Net Standard
Testing on the Android Emulator (8.0, API26) and a Google Pixel (8.1 API27), both have the same issue.
I use NavigationPage and Navigation.PushAsync to move between pages (therefore have navigation bars on every page).
I want to create an auto populate field control, the user types in the first few letters and I look up the results in a database / static list of string and display the results below for the user to click/tap.
I have this working using a composite control (the contents of the frame marked interesting below).
The problem I have is scrolling the view to show the results.
My page has this layout hierarchy:-
ContentPage
StackLayout
ScrollView
StackLayout
Frame (some label and entry fields inside a stack layout)
Frame (some label and entry fields inside a stack layout)
Frame (some label and entry fields inside a stack layout)
Frame (the interesting one that deals with scrolling)
StackLayout
Heading Label
StackLayout
Label x:Name="ScrollToLabel"
Entry x:Name="ScrollToEntry"
Grid x:Name="ScrollToGrid"
Entry x:Name="Hidden" Text="I should stay visible as you type"
/StackLayout
/StackLayout
/Frame
Frame (some label and entry fields inside a stack layout)
Frame (some label and entry fields inside a stack layout)
/StackLayout
/ScrollView
StackLayout
Button Text = Done
/StackLayout
/StackLayout
/ContentPage
When the user clicks/taps in to ScrollToEntry, the keyboard opens and pans the control to above the keyboard (ok so far).
When the user starts typing in ScrollToEntry, the code populates ScrollToGrid with up to 5 results.
At this point I want to make sure that the grid results are visible for the user to tap on.
I have tried 2 different options, ScrollToAsync(ScrollToLabel, Start) and ScrollToAsync(Hidden, MakeVisible).
Neither work as I would like 100% of the time.
ScrollToAsync(ScrollToLabel, Start)
If the ScrollToEntry is at the bottom of the screen, the navigation bar is hidden and the view pans up too far.
The ScrollToLabel is now off the top of the screen.
When the second letter is clicked/tapped, the Navigation bar is restored and the scroll scrolls correctly, ScrollToLabel at the top of the screen.
If the ScrollToEntry is near the top of the screen, the navigation bar is not hidden and it scrolls correctly.
ScrollToAsync(Hidden, MakeVisible)
This is my preferred option because it would only scroll as far as needed to display all the results (not all the way to the top).
This works even worse than the first one.
In most cases, it does not scroll at all, I assume it thinks it already visible but is actually behind the keyboard?
If it does scroll, the label Hidden is still not displayed (I tested with both a HeightRequest="0" version and a visible version, both the same result).
I tried using the below code to change the adjust to resize.
Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
2 issues,
1. Because it resizes, the Done button now is above the keyboard, taking up space.
2. When clicking the hardware back button (not the done or navigation back button) the previous view now has a white space where the keyboard was.
If using the done or navigation back, the screen initially appears with the white space but then refreshes to full screen.
I have created a sample app that highlights the issues (by default using pan, not resize).
It's the most simple version of the layout I'm using...
Am I doing something wrong or is this just how it works? If its how it works, this must be a bug? If I'm doing it wrong, can someone tell me what or suggest a different way of doing it?

iOS 11 iPhone X toolbar not respecting safe areas

I have noticed that in the simulator using iPhone X, the tabBar increases dimension vertically to respect the safe area on the bottom of the screen. However toolbars added in storyboard do not and still maintain their default 44 height which causes the toolbarItems to be cutoff on the edges.
How would I duplicate the tabBar behavior for the toolbar on iPhone X without customizing the toolbar?
In order to be able to constrain items to the safe area in a storyboard, you need to enable "Use Safe Area Layout Guides" on the storyboard, in the Interface Builder Document section:
Once you've done that, you can, as mentioned in the other answer, constrain to the Safe Area:
The solution is to change the vertical constraint in storyboard on the bottom and sides to the safe area rather than container margin:

XCode 5 - Constraints not always kept at runtime when using a Tab View Controller

In Xcode 5, I've opened a new project and added the following:
A Tab View Controller with two Tabs (thus two View Controllers).
In each Controller View, I've added a CollectionView, with both a Label and a Button under it.
I've applied the Default constraints. No warnings.
... clicked Run.
In the iOS simulator, the first Tab looks ok, all elements in the View are aligned to the bottom of the layout, which is the top of the tab bar. Perfect.
When clicking on the second Tab, instead of aligning to the bottom of the layout, it aligns everything to the bottom of the container. So all the elements in the View drop in height by that much. Clicking back to the first tab will now show this incorrect positioning as well.
Strangely, rotating the device fixes this... showing the correct alignments in both tabs and for both orientations.
Any idea what am I doing wrong?
Thanks,
I now believe this is a bug in XCode 5.
I got around it by replacing the constraint for a pin, like so:
Editor -> Pin -> Bottom Space to Superview.

How to add icons to tabbar items via the GUI designer

I have an iOS6 iPhone application, with a Tabbar and tabbar buttons. These buttons need icons and that's where the trouble starts. Added one icon to the project, double clicked on a button in the designer and associated the (questionmark) icon via the image combobox to the button. When I run the app on my iPhone, I do indeed see that the button now does indeed display a gradient-gray square, which turns into a gradient light-blue square, but the questionmark icon is not shown. The icon is a .png and the size is width 40, height 51. I changed nothing in the code.
I solved my problem to the extent that I can work with it: you need so called 'transparent icons'.

iOS MonoTouch navigation middle buttons

Some Apps (like Facebook's) have buttons in the middle of the navigation section (instead of text title). How could I support right/left, and add middle button region the navigation menu, in MonoTouch?
You need to create a view or a toolbar or basically what you want that is a subclass of UIView, and add the following code.
(don't forget that you uiviewcontroller should be embedded in uinavigationcontroller)
this.NavigationItem.TitleView = YourTitleView;

Resources