I want to add UISearchbar with two scoop button to my UIView. i do not want to either navigation or table view.
when user open model view page from sheet comes up with Search option and rest. when user click on Search button scoop button to be visible.
i tried to do but i am not getting desire result.
how to remove Background of scope button, i have removed uisearchbar, similar way i do not want white background for button. is it possible. showsScopeBar i am making FALSE still background can be visible.
To remove Background image of scope buttons just try :
Class segmentedControlBackgroundView = NSClassFromString(#"_UISegmentedControlBackgroundView");
for(UIView *view in self.searchBar.subviews) {
if([view isKindOfClass:[UISegmentedControl class]]){
for(UIView *subview in view.subviews) {
if ([subview isKindOfClass:segmentedControlBackgroundView]) {
subview.hidden = YES;
}
}
}
}
Related
I have my UISearchBar placed in a navigation bar. When I tap on the bar, it expands itself and shows the cancel button. If you type something in the field and then you tap on "Search" on the keyboard, it dismiss the keyboard showing you the results. But in this moment I'm having a big problem : the cancel button is now disabled (greyed out) and if I tap on it, first the keyboard is opened and then I can tap again on the Cancel to exit from the search. Is it possible to keep the Cancel button active always so I can directly tap on it to exit from the search?
searchBar.showsCancelButton = YES;
You can create another custom button on UISearchBar.
for (UIView *subView in searchBar.subviews) {
if([subView isKindOfClass:[UIButton class]]) {
UIButton *cancelButton = (UIButton *)[searchBar.subviews lastObject];
//Make changes to the cancelButton here
[cancelButton setEnabled:YES];
}
}
I have UISearchBar, i setted correctly desired color on it.
Like in below picture:
When i start to writing on searchBar(while start editing) searchBar color changed.
Like in below picture:
I want to searchBar color do not change when start writing on searchBar.
How can i ensure that?
I found solution for this problem. My solution like below:
+ (void)removeUISearchBarBackgroundInViewHierarchy:(UIView *)view {
for (UIView *subview in [view subviews]) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
break; //To avoid an extra loop as there is only one UISearchBarBackground
} else {
[self removeUISearchBarBackgroundInViewHierarchy:subview];
}
}}
Ok, so I've got a UITableView below a UISearchBar. Above that is just some UILables and UIButtons and then the UINavigationBar.
The UISearchBar has the scope bar enabled. Whenever I tap on the search bar I get the following odd behaviour (I've got the on screen keyboard disabled but the focus is in the UISearchBar text field):
Where as normally it looks like this:
It's really frustrating and I can't work out why it's happening. Has anybody experienced anything similar and found a solution?
Thanks!
It's a bodge, but it's the best I could come up with. I just put the following in viewWillAppear and then manually created a background image of 44px high and put it behind the UISearchBar on the storyboard.
-(void)viewWillAppear:(BOOL)animated
{
[self.searchBar sizeToFit];
for (UIView *subview in self.view.subviews) {
for(UIView *subView2 in subview.subviews){
for(UIView *subView3 in subView2.subviews){
if ([[[subView3 class] description] isEqualToString:#"UISearchBarBackground"]) {
[subView3 removeFromSuperview];
break;
}
}
}
}
}
I want to change the selected scope after user has selected something from a table view.
I have tried this:
for (id view in [self.searchDisplayController.searchBar subviews]) {
if ([view isMemberOfClass:[UISegmentedControl class]])
{
UISegmentedControl *scopeBar = view;
scopeBar.selectedSegmentIndex = 1;
}
}
But the scope button i want is still not selected. My search bar doesn't have a subview of class UISegmentedControl.
I assume you mean the scopes of an UISearchBar and you already have your UISearchBar set up so it shows scopes.
The UISearchBar has a special property that needs to be set:
self.searchDisplayController.searchBar.selectedScopeButtonIndex = 1;
I've looked through various SO questions on the topic and I have not found a solution. I have a UIViewController with a UITableView and a UICollectionView. I want the UICollectionView to scroll to the top, when the user taps it.
The documents say if you have more than one UiScrollView subclass - you need to set them to no and the UiScrollView you want to scroll to the top, to yes.
So I wrote this bit of code to go through all my views:
for (UIScrollView *view in self.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
view.scrollsToTop = NO;
}
}
self.collectionView.scrollsToTop = YES;
This way I am sure any subclass of UiScrollView has it's scrollsToTop property set to no.
However tapping on the status bar does not do anything.
Can someone tell me what I am missing here?
Thank you
It seems that you are only iterating through the subviews of your main view. Your UITableView may be nested inside another view. Try doing the following;
//in view did load
[self setScrollToTopFalse:self.view];
self.collectionView.scrollsToTop = YES;
-(void)setScrollToTopFalse:(UIView *)v
{
for (UIView * v1 in [v subviews]) {
if ([[v1 class]isSubclassOfClass:[UIScrollView class]]) {
((UIScrollView *)v1).scrollsToTop = NO;
}
[self setScrollToTopFalse:v1];
}
}