Why SearchBar color changed while editing? - ios

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];
}
}}

Related

UISearchBar on UITableView with scope bar resizes itself over other UI items

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;
}
}
}
}
}

Adding UISearchBar with Scope button as subview to UIView

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;
}
}
}
}

Remove line UISearchBar with UISearchDisplayController when remove the background color

I have added with help of interface builder a UISearchBar With UISearchDisplayController in my UITableView. I know how to set the background color of UISearchBar, I do it this way:
for (UIView *subview in self.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
}
}
but you can see, there is a line, that I can't understand , and how to remove it, that scroll with the searchbar:
if I insert with interface builder only a UISearchbar without UISearchDisplayController there isn't that line, how I can remove that line?
Use this instead:
for (UIView *subview in self.searchDisplayController.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
}
}
When we use UISearchDisplayController, the searchBar gets associated with the searchBar property of UISearchDisplayController and can be accessed using self.searchDisplayController.searchBar
I am using 1px image with 0% opacity (image)
self.searchDisplayController.searchBar.backgroundImage=[UIImage imageNamed:#"image"] ;
and its work perfect as what you want.

UIPanGestureRecognizer + UIViewController

I am adding a UIPanGestureRecognizer to a partially hidden UIViewController (it is there to pull it back on screen). All is working fine except on the odd occasion when the UIViewController has a scrollable subView (i.e. UIScrollView, UITableView). I can't set useInteractionEnabled = NO because this disables my gesture... Any suggested workarounds?
EDIT:
I have this work around and it is achieving what I want...
for(UIView *subView in sender.view.subviews) {
[subView setUserInteractionEnabled:NO];
}
But I feel there should be a better solution?
The best I have come up with is
for(UIView *subView in sender.view.subviews) {
[subView setUserInteractionEnabled:NO];
}

Autocorrect issue with a colored UITextview

I'm using in my app a textview with blue colored background.
When autocorrect is enabled, whenever it corrects a word a white box forms around the word and the text's color changes also.
Any ideas on how to stop this effect?
Nope, I think you can't change the color of the overlay or the textcolor out of the box..
This is a hard one, if you put a breakpoint in - (void) layoutSubviews {..} of your view you'll see UIKit has drawn a 'UITextSelectionView' above the text...
I tried to subclass UITextView to see if its layoutSubviews get's fired and it seems it does!
So I tried to remove the overlay:
- (void) layoutSubviews {
[super layoutSubviews];
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:#"UITextSelectionView"]) {
DLog(#"Subview %#", [subview debugDescription]);
[subview removeFromSuperview];
break;
}
}
}
And it worked.. but that results in missing the cursor, and disabling any selection :(
I think you'll have to disable autocorrect..
I'll re-start the bounty if someone finds a real answer!
This may have other side effects I am currently investigating what else calls this, but overriding firstRect(for range) in UITextView and returning CGrect.Zero removes the highlight.
override public func firstRect(for range: UITextRange) -> CGRect {
return CGRect.zero;
}

Resources