Have ViewController with SearchBar.
After click search button appears SearchBar with focus
How to hide 2 segmented controls "Title"?
Alternate to Jeff's answer
If this code segmentedControl.hidden = YES; is not working.. Then Embed the segment control inside UIView and hide that view like this,
view.hidden = YES;
You need to hide the UISegmentedControl, as a UIView subclass it has a hidden property.
segmentedControl.hidden = YES;
I am adding Swift 3 solution so that it will be useful for others. In Swift 3, you can hide UISegmentedControl like this
segmentedControl.isHidden = true
Related
Resizing UISearchBar in UINavigationBar titleView doesn't work.
I also got two navigation items on each side of the UINavigationBar.
#IBAction func searchButtonPressed(sender: UIButton) {
searchWrap.frame = self.resultSearchController.searchBar.bounds
searchWrap .addSubview(self.resultSearchController.searchBar)
self.resultSearchController.active = true
self.resultSearchController.searchBar.becomeFirstResponder()
if (UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
self.tableView.tableHeaderView = searchWrap
}
else
{
self.navigationItem.titleView = searchWrap
}
searchIsOn = true
searchButton.hidden = true
filterButton.hidden = true
favButtonStar.hidden = true
settingsButton.hidden = true
}
even if set the frame it automatically resizes.
Here I have created a Demo project for the above solution which you can get it from here.
Download Demo Project
What I have done?
First, I added two buttons to UINavigationBar. First button is for demo and second is for search.
When you tap on search a UISearchBar will be added to the titleView of UINavigationBar and the buttons will be removed from the UINavigationBar
I have implemented the cancel delegate of UISearchBar, when it is called I removed UISearchBar and added the earlier two buttons again.
This how you can get the full UISearchBar
I have met this issue once. And confirm that searchBar that is added as subview on titleView does not work.
titleView belongs to self.navigationController, and your searchDelegate you're using belong to self controller, that's not self.navigationController. So it can not reach into delegate even in debug.
I don't know what your aim, but if you really want to on the navigationBar, you could pretend that, make a view look like a navigationBar, and add searchBar like subview and so on.
Hope this could help.
I have created a custom inputView for my UITextField. The view itself looks and functions great, but on the iPad I'm getting undo, redo, and paste buttons above my custom inputView. How do I remove those buttons? They don't have any functionality, but they should be removed.
With Swift 3 and XCode 8 I was able to remove the bar by removing the two button groups on the text field input:
self.textField.inputAssistantItem.leadingBarButtonGroups.removeAll()
self.textField.inputAssistantItem.trailingBarButtonGroups.removeAll()
// hide undo, redo, paste button bar for textfield input view
UITextInputAssistantItem* item = [your_textfield inputAssistantItem];
item.leadingBarButtonGroups = #[];
item.trailingBarButtonGroups = #[];
will hide the top bar for input view.
Reference:How to hide the shortcut bar in iOS9
Try removing the inputAccessoryView:
self.textField.inputAccessoryView = nil;
I want to developer app with a custom navigation bar like in the following images:
I think that i need to subclass UINavigationBar and add button to centre of nav bar, but i don't really know how to make navigation bar look like on image. Can you please give me advice what should i do, links to any kind of documentation would be awesome!
Similar questions about navBar that doesn't helped me:
ios back button in the bar
Use custom Navigation Bar in iOS
Custom Navigation Bar in iOS 5
rogcar
EDIT:
My idea is next: make custom navigation bar height little bigger than default size, and add background image with arrow in it and with some transparency on the edges.
If you want a button (you probably do want) you can achieve it completely by subclassing UINavigationBar. You should remember that height of UINavigationBar is read-only property.
Style but not tappable:
So let's assume we subclass the navigation bar and add button there. You could do this and it will be going look great. For example:
- (void)drawRect:(CGRect)rect
{
self.backgroundColor = [UIColor lightGrayColor];
UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width/2-50, 0 , 100, 100)];
[myButton setBackgroundColor:[UIColor lightGrayColor]];
[myButton setTitle:#"Normal" forState:UIControlStateNormal];
[myButton setTitle:#"Highlighted" forState:UIControlStateHighlighted];
[self addSubview:myButton];
[self sendSubviewToBack:myButton];
}
But you will facing a problem that your button is non tapeable below UINvaigationBar. (I post an image on the bottom of the answer)
So there is clearly not a path you want to follow. Don't even try that.
Style but not tappable 2:
You may override this method in your navigation bar subclass
- (CGSize) sizeThatFits:(CGSize)size {
return CGSizeMake(custom_width, custom_height);
}
And then mask it using UIBezierPath for example
The right (tappable) way:
You have to create a view stick to your UINavigationBar. What i will do here (if you want it to every screen) is:
Make a Category of UIViewController which can draw (for example - this is easiest way) UIButton.
Style this 'UIButton' whatever you want (if you want
Pin action to 'UIButton': [btn addTarget:self action:#selector(menuShow:) forControlEvents:UIControlEventTouchUpInside];
menuShow: method should be declare in your category
You can call drawing button every time you want to redraw view controller.
As you can see there there will be two separates View: UINavigationBar and UIButton. This is allow you to set content under this little button and make it tapable.
So why just don't hide navigation bar, and use different view? Because iOS7 ;) When Apple change it in iOS7 for example then you have to rebuild your pseudo NavigationBar, with only additional view, you don't need to do anything.
You do not need to subclass UINavigationBar. Create UIView add to it UIImageView as background with image in the shape you need, add button.
Subclass UINavigationController hide UINavigationBar, add custom navigation bar.
First Hide navigation bar using -
self.navigationController.navigationBarHidden = YES;
Then create UIView with required height,height of navigationBar is 44px.Then create background image view, object of required UIButton and add all objects on created UIView as a subview.It will look like navigationBar.Thank you.
You can add your custom shaped view as titleView on the navigation bar.
Just make sure that clipsToBounds is set to NO, so it doesn't get clipped.
How can I create a popup window like in this picture:
I can create UIView and show it with a toolbar and tableview but I don't know how can I show a black overlay and is there a simple way to do this?
That is just an UIViewController with the modalPresentationStyle property set UIModalPresentationPageSheet or UIModalPresentationFormSheet
I give you simple trick:
Create one custom UIView (dimView) which frame is similar to window.bounds and BackGroundColor is black and alpha = 0.5f;
Add another custom UIView with on UITableView which style is grouped and also you need to add UINavigationBar with done UIBarButtonItem
And add your custom controls on UITableView's cell.
I would like to hide back button of navigation bar which is a part of Story board, I have tried different following code snippets in detail view button nothing seems to work for me.
self.navigationItem.hidesBackButton = YES;
self.navigationItem.backBarButtonItem=nil;
PS: I am also having tab bar along with navigation bar in my story board
Add this line in the viewDidLoad of your ViewController where you would like to hide the back bar button:
[self.navigationItem setHidesBackButton:YES];
Tested successfully in a storyboard project.
Try this
self.navigationItem.hidesBackButton= YES;
If you have added your own button to the navigationController and want to hide that as well (such as while editing text), its a two line process like this:
myViewController.navigationItem.leftBarButtonItem = nil;
myViewController.navigationItem.hidesBackButton=YES;
You can hide the entire navigationbar as follows:
self.navigationController.navigationBar.hidden = YES;
then in your storyboard you can add a navigation bar to your view controller.
The result is what you want but maybe users will be confused as to why they can't go back...
Its too late answer but may help others.
To hide back button you can do this :
self.navigationController.navigationItem.leftBarButtonItem.hidden = YES;
You can also try with :
self.navigationItem.leftBarButtonItem.hidden = YES;
This actually hides left BarButton and back button is on left side, too, unless you change programmatically.