Getting Autolayout beneath the status bar - ios

I have read multiple previous posts on Autolayout and the status bar behavior in iOS 7 and still do not know how to get my Autolay-ed out objects to be beneath the status bar.
I currently have
self.automaticallyAdjustsScrollViewInsets = YES;
self.edgesForExtendedLayout = UIRectEdgeNone;
and a search bar has a visual format applied like V:|-0-searchBar-|.
The search bar renders under the status bar like
as expected.
I have been unable to find a solution to get the search bar to start at the bottom edge of the status bar. How can this be done?
EDIT: I have looked at the top layout option, but I have a xib for my Custom View Controller. There is no top layout guide available. How can I support this setup? I would like to avoid checking the system version.

You need to use the topLayoutGuide.
Apple has a great guide on this issue: https://developer.apple.com/library/ios/qa/qa1797/_index.html

I was able to programmatically access the top guide by following this answer. I was using XIBs for my custom class and thus could not access the topLayoutGuide through the graphical interface builder as seen below.
Instead topLayoutGuide can be accessed through [self topLayoutGuide], where self is the UIViewController. Documentation link
if ([self respondsToSelector:#selector(topLayoutGuide)]) {
id topGuide = [self topLayoutGuide];
NSDictionaryOfVariableBindings(topGuide ...

Related

iOS 11 SearchDisplayController shows black status bar

I know SearchDisplayController is deprecated, but Storyboard still supports it, and it is an easy way to present tableViewController on top of your view controller. I have been using it, and I would still prefer to use that. And in iOS 11, when I run my app, the status bar of the SearchDisplayController. after the search bar is focused, is pitch BLACK. Does anyone know how to solve this bug? Also if you realize, the margins of the searcher is off. I am using the default iOS 11 searchbar. Below is attached screenshot:
Have you tried to set the extendedLayoutIncludesOpaqueBars property to true?
searchDisplayController.extendedLayoutIncludesOpaqueBars = true
This is not the best solution actually, but It works to change status bar color.
if let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView {
statusBar.backgroundColor = //YOUR COLOR HERE
}
Keep in mind this will affect the whole app. If you need to change some views only then save the previous color to restore it.
Regards.

Tweak UI Navigation on iOS 11

I have a problem with a navigation bar in iOS 11.
I use this code:
[UINavigationBar appearance].prefersLargeTitles = YES;
...to set a new style for my app. It works well untill a user pull to refresh on the table view; then it breaks.
This is before pull-to-refresh:
...and this is _after:
Note: I use the table view controller's built-in pull-to-refresh control.
I searched for a solution but it still eludes me. If someone knows how to fix this please drop some advice.
Thanks for the support :)
I have catch this bug too, and we have found the solution.
You must constraint your UITableView to superview (contentView of your view controller), after that large title and all related views starts to work correct.
Like this:
While I do not claim this is the solution for every situation the error occurs in, setting the navigationBar's isTranslucent property to true (which is also the default value) fixed the problem for me.
If you want to keep your navigation bar non-translucent you can use the following code:
navigationBar.barStyle = .blackOpaque

How to create a fixed navigation bar iOS Swift

I want to create a fixed header that doesn't scroll with tableViewCells, or other content that I have. The header should stay in place fixed, just like in most iOS apps.
Here is the image of the issue I'm facing:
I tried embedding it in a NavigationController & a TabViewController. That didn't work.
I also tried adding a scroll-view.
I referred to this link but it's outdated and didn't help: how iphone facebook app make the navigation bar fixed
Thanks.
I'd really recommend fooling around with the Navigation controller until you figure it out, it's really the best method for this. If you've embedded it, I'd check out your view with the Attributes inspector, to make sure everything needed is enabled.
HOWEVER, there is another way I've used before. Create a new ViewController, and create two views inside of it. One will be your FakeNavBar, and the other will be a container/TableView that'll hold your data.
Once you've added both these to your new VC, just set them up normally, and bingo!
One tip for this, is that NavBar is typically 64 points high, so your fake bar will be something like this:
fakeNavBar.frame = CGRectMake(0, 0, theWidth, 64)
tableView.frame = CGRectMake(0, 64, theWidth, theHeight-64)
And your view hierarchy will look like this:

How do i Create "Slide-Out Navigation Panel" with Non movable(Fixed) UINavigation Bar in iOS?

In one of my app i want to create Side left menu as many popular app provide.
I have already done it my projects using PPRevealSideViewController.
But the issue is it is not supported with Non movable UINavigation bar.
It only supported with Below UI.
Whereas Below is My requirement.
Requiremt is: Top UInavigationBar must be Non movable and fixed and another ViewController slide the FirstView Controller.
I tried to hack with the library But till now not able to reach to my requirement.
Does any of you have done similar thing? Or any suggestions?
Any Help will be appreciated.
Thanks & Regards,
Jenifer.
Find Demo of similar 3rd party Library named as CCKFNavDrawer.
You need to do some settings with this as below:
In CCKFNavDrawer.m class add below code once in viewDidLoad: method
self.shawdowView.backgroundColor = [UIColor clearColor];
and comment else where ,
set ContentInset as Below:
[self.drawerView.drawerTableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
Change Below stuff:
self.outFrame = CGRectMake(-self.menuWidth,64,self.menuWidth,self.meunHeight);
self.inFrame = CGRectMake (0,64,self.menuWidth,self.meunHeight);
Tell me if you need more help regarding this.

Why UISearchBar and its scope buttons are shown in one line?

I have seen Apple's example "TableSearch" that when touched its scope buttons come below the search bar.
http://developer.apple.com/iphone/library/samplecode/TableSearch/Introduction/Intro.html
But when I make my own it looks good at first but when I touch it looks like ugly, scope buttons and search bar are shown in the same line like this:
http://cl.ly/BN9
What do I have to do make it like "TableSearch" example in the iPad?
I am doing everything in IB and tried to modify the search bar programatically from the controller:
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.rowHeight = 88.0f;
self.tableView.contentOffset = CGPointMake(0, self.searchDisplayController.searchBar.frame.size.height);
self.searchDisplayController.searchResultsTableView.rowHeight = self.tableView.rowHeight;
//BELOW DID NOT WORK:
CGRect b = self.searchDisplayController.searchBar.bounds;
self.searchDisplayController.searchBar.bounds = CGRectMake(b.origin.x, b.origin.y, b.size.width, self.tableView.rowHeight);
b = self.searchDisplayController.searchBar.frame;
self.searchDisplayController.searchBar.frame = CGRectMake(b.origin.x, b.origin.y, b.size.width, self.tableView.rowHeight);
//BELOW WORKS PERFECT BUT IS A PRIVATE METHOD, HENCE I AM NOT SUPPOSED TO USE IT
//[self.searchDisplayController.searchBar setCombinesLandscapeBars:NO];
}
Thanks in advance.
I've encountered this bug as well, and I've both filed a report with Apple and requested technical assistance. I'll let you know how it goes. In the meantime I'll give you a brief bit of background on this bug.
On the iPhone, to preserve precious vertical screen real estate in Landscape mode, the UISearchDisplayController sets the UISearchBar to combine its search bar and search field in a single horizontal layout. This works pretty well because of the increased horizontal size of the screen (480 points in Landscape). Unfortunately, it works not so well on the iPad, where in Landscape mode the UI change really isn't necessary in the first place because you have plenty of vertical real estate. You also still only have 320 pixels of horizontal display space in the master view of the UISplitViewController, not the increased 480 of the iPhone. The result is an iSore.
Presumably the problem is that UISearchDisplayController is behaving badly in its willRotateToInterfaceOrientation:duration‎: method. Specifically, it's not bothering to check whether it's on an iPhone or not before it sets the combinesLandscapeBars property on its UISearchBar. The private API kludge in your code works because it fixes that oversight in the UISearchDisplayController. But of course Apple will rain down the fury of the ancients on you for using undocumented APIs, so you can't. Really we're at the mercy of Apple on this one.
If you're willing to give up the eye-candy and convenience of UISearchDisplayController, you can use a UISearchBar sans UISearchDisplayController and manage aspects of presentation yourself. Obviously this requires a lot more code and would be pointless if Apple's API engineers did their jobs, but it will at least resolve the display bug.
If you're Apple you can use your own undocumented APIs, which is why Mail.app doesn't have this problem.
UPDATE
The bug report I've filed with Apple is #8344719.
Using the following code, you will not get warning:
if ([self.searchDisplayController.searchBar respondsToSelector:#selector(setCombinesLandscapeBars:)])
{
objc_msgSend(self.searchDisplayController.searchBar, #selector(setCombinesLandscapeBars:), NO );
}
When you set the bounds and frame for the searchBar, like for the frame here:
blabla.searchBar.frame = CGRectMake(b.origin.x,
b.origin.y,
b.size.width,
self.tableView.rowHeight);
it seems like there is a problem with height. Scope buttons require some space under the search bar, so you should increase the height of both bounds and the frame.
If you show and hide scope buttons on some event you need to adjust the frame size each time.
I'm getting this issue on an iPad, but I can get it to work if I insert this in my implementation file:
#synthesize tableView;
I'm guessing there is something bad with the XIB being loaded, but I don't know why this would fix it.

Resources