UIsearchbar show a line below it which never goes - ios

I have a UISearchBar whose bartintcolor i have changed and have cancel enabled. This is added as a subview of a UIVew.
whenever make search bar visible, it shows a black line below it which never goes away.
Am i missing something about UISearchbar appearence or its background view.
dummyview=[[UIView alloc]initWithFrame:CGRectMake(10, 30,self.headerView.frame.size.width-20, 30)];
[dummyview setBackgroundColor:[UIColor redColor]];
[dummyview setClipsToBounds:TRUE];
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, dummyview.frame.size.width, dummyview.frame.size.height)];
self.searchBar.delegate = (id)self;
[self.searchBar setPlaceholder:#"Search"];
self.searchBar.showsCancelButton = YES;
_searchBar.barTintColor = [Utilities colorWithHexString:#"3a7ebc"];
[[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor whiteColor]];
_searchBar.delegate=self;
[dummyview addSubview:_searchBar];
it gives me like this
if i change background to native one, i get displaced content.
// _searchBar.barTintColor = [Utilities colorWithHexString:#"3a7ebc"];
I just dont want the black line below the searchbar.
Updated:
using
_searchBar.searchBarStyle=UISearchBarStyleMinimal;
_searchBar.barStyle=UIBarStyleDefault;
result in this
So
finally everything done
_searchBar.searchBarStyle=UISearchBarStyleMinimal;
_searchBar.barStyle=UIBarStyleDefault;
UITextField *searchField=[_searchBar valueForKey:#"_searchField"];
if (searchField) {
[searchField setTextColor:[UIColor whiteColor]];
}

Put my code in viewdidload or viewwillappear method.
searchbar.barTintColor=[UIColor samebgcolor];
searchbar.layer.borderWidth = 1;
searchbar.layer.borderColor = [[UIColor samebgcolor] CGColor];
I would also consider, "I hope this will help you", as this is the strongest, and hopes that the thing will most definitely, certainly help.
If you like my Answer so accept and upvote my answer

Related

Cannot change searchbar text color, but I am able to change background color

I have a searchbar embedded in a navigationbar. I'm able to change background color, but for the life of me cannot change text color. I have the following code in my viewdidload. What is missing to get the text to change?
if(!itemSearchBar)
{
itemSearchBar = [[UISearchBar alloc] init];
[itemSearchBar setFrame:CGRectMake(0, 0, self.view.frame.size.width, 55)];
itemSearchBar.placeholder = #"What are you looking for?";
itemSearchBar.delegate = self;
UITextField *txfSearchField = [itemSearchBar valueForKey:#"_searchField"];
txfSearchField.backgroundColor = [UIColor colorWithRed:130/255.0 green:58/255.0 blue:23/255.0 alpha:1.0];
UISearchDisplayController *searchCon = [[UISearchDisplayController alloc]
initWithSearchBar:itemSearchBar
contentsController:self ];
[searchCon setActive:NO animated:YES];
self.searchDisplayController = searchCon;
self.searchDisplayController.delegate = self;
self.searchDisplayController.searchResultsDataSource = self;
self.searchDisplayController.searchResultsDelegate = self;
self.searchDisplayController.displaysSearchBarInNavigationBar=YES;
I've read that the following should work but doesn't:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor blueColor]];
I've also tried:
itemSearchBar.tintColor = [UIColor redColor];
txfSearchField.textColor = [UIColor redColor];
Any suggestions???
I think you are looking at the color of placeholder text and not typing anything in the textfield. Otherwise, your code seems correct. The method
txfSearchField.textColor = [UIColor redColor]
must work. Type anything in the field and you will see red color.

UITextView responding to touches, but keyboard doesn't appear

I can't comprehend it. I have a uitextview which animates upward when it begins editing to make room for the keyboard. I tap the uitextview and registers that it has begun editing and it animates up but the keyboard doesn't appear. This has never happened before and I've tested the app hundreds of times. I even have the textview become first responder upon building the view and the keyboard still doesn't show.
I have the .m file and .h file as so that is not the issue..
Here is the set up code:
self.addDescriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 470, 320, 100)];
[self.addDescriptionTextView setBackgroundColor:[UIColor colorWith8BitRed:0 green:0 blue:0 alpha:.5]];
[self.addDescriptionTextView setTextColor: [UIColor whiteColor]];
[self.addDescriptionTextView setFont:[UIFont fontWithName:#"Verdana" size:16]];
[self.addDescriptionTextView setDelegate:self];
self.addDescriptionTextView.textContainer.maximumNumberOfLines = 10;
[self.addDescriptionTextView.layoutManager textContainerChangedGeometry:self.addDescriptionTextView.textContainer];
[confirmView addSubview:self.addDescriptionTextView];
I ran your code on my iOS device and the keyboard came up,
Heres the viewDidLoad Code I ran,
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.addDescriptionTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 470, 320, 100)];
self.addDescriptionTextView.backgroundColor = [UIColor redColor];
[self.addDescriptionTextView setTextColor: [UIColor whiteColor]];
[self.addDescriptionTextView setFont:[UIFont fontWithName:#"Verdana" size:16]];
[self.addDescriptionTextView setDelegate:self];
self.addDescriptionTextView.textContainer.maximumNumberOfLines = 10;
[self.addDescriptionTextView.layoutManager textContainerChangedGeometry:self.addDescriptionTextView.textContainer];
self.addDescriptionTextView.editable = YES;
[self.view addSubview:self.addDescriptionTextView];
}
Try adding the UIView.editable line but it should be set to yes automatically.
It might have something to do with confirmView?
Also try changing the UIColor Background colour line I was getting errors with your one.
Edit: After running on iPhone4s your problem is the position you initiate the UIView (to see try changing the 470 to 0 in the CGRect to see the bug)

UISearchBar text color when used in UISearchDisplayController

i'm trying to change a UISearchbar text color in iOS7 app. (i want the text to be white).
the search bar is attached to a searchDisplay controller.
i have tried many options, including this one:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], [FVRNavigationBar class], nil] setTextColor:[UIColor whiteColor]];
also tried setTintColor:, and setBarTintColor:. Nothing works.
Note, this solutions does work when the search bar is not attached to a displayController.
FYI, not that i think it matters, but i use a background image for my search bar.
in addition, the searchbar is placed in my navigationBar.
here is my code:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], [FVRNavigationBar class], nil] setTextColor:[UIColor whiteColor]];
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 52)];
[_searchBar setSearchFieldBackgroundImage:[IMAGE(#"searchBarBg") resizableImageWithCapInsets:UIEdgeInsetsMake(8, 8, 8, 8)] forState:UIControlStateNormal];
_displayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
_displayController.delegate = self;
_displayController.displaysSearchBarInNavigationBar = YES;
I'd appreciate anyones help. thanks!

Colour changed in iOS7.1, how to change searchBar colour?

On iOS7.0.3 - 7.0.6, my searchBar colour is Gold/yellow colour like this:
But on iOS 7.1, colour becomes like this:
I set
searchBar.tintColor = [UIColor clearColor];
searchBar.backgroundColor = goldColor;
searchBar.tintColor = [UIColor blackColor];
I've tried so many ways and all are failed. Can anyone figure out what changes in iOS 7.1?
============== My fix ===============
I fix this problem by covering a view on searchBar and add the search text filed as subview on this new view.
I need point out that the gold status bar is a subView of searchBar, and it's frame is CGRectMake(0, -20, 320, 20) and it's background colour is gold.
At first, I set this:
_searchBar.translucent = YES;
_searchBar.scopeBarBackgroundImage = [self imageWithColor:UWGold];
and looks like this:
Then, I expand the view cover the status bar, I changed the view's frame.size.height + searchBar's height, then use this line:
UITextField *textSearchField = [_searchBar valueForKey:#"_searchField"];
to get the textSearchField, then add this textSearchField to the cover view.
At last, the searchBar is exactly like when on iOS 7.0
Not a good way, I need figure out what changes on iOS 7.1 and use a right way to implement this.
Try this:
if(IOS_7)
{
self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
self.searchBar.backgroundImage = [UIImage imageWithColor:[UIColor redColor] cornerRadius:5.0f];
}
Hopefully this will help you.
None of the above answers worked for me on iOS 7/8. Here's some setup code that did the trick:
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 44)];
searchBar.scopeButtonTitles = #[#"Scope1", #"Scope2"];
searchBar.selectedScopeButtonIndex = 0;
searchBar.backgroundColor = [UIColor clearColor];
searchBar.barTintColor = [UIColor clearColor];
searchBar.translucent = YES; // SUPER IMPORTANT, REMOVING THIS MESSED UP THE SCOPE BAR
// ONLY USE IMAGES, NOT BACKGROUND COLORS
UIImage *searchBarBackgroundImage = [[UIImage imageNamed:#"SearchBarBackgroundImage"];
UIImage *scopeBarBackgroundImage = [[UIImage imageNamed:#"ScopeBarBackgroundImage"];
[searchBar setBackgroundImage:searchBarBackgroundImage
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
searchBar.scopeBarBackgroundImage = scopeBarBackgroundImage;
searchBar.tintColor = [UIColor whiteColor];
I used next approach for changing backgroundColor of searchBar
1.As suggested by #Ben Jackson - set BackgroundImage
[self.searchBar setBackgroundImage:[self imageWithColor:[UIColor blueColor]] forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
2.Change textField to what u need according to design
NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
for( int i = 0; i < searchBarSubViews.count; i++) {
if([[searchBarSubViews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
UITextField *searchTextField = (UITextField *)[searchBarSubViews objectAtIndex:i];
[searchTextField setTintColor:[UIColor blueColor]];
searchTextField.placeholder = #"Search";
searchTextField.backgroundColor = [UIColor whiteColor];
searchTextField.layer.borderColor = [UIColor blueColor].CGColor;
searchTextField.layer.borderWidth = 1.0f;
searchTextField.layer.cornerRadius = 8.0f;
searchTextField.leftViewMode = UITextFieldViewModeNever;
}
}
Also method for image from color - here
Result:

How to create a multiline navigation bar similar to the one in WhatsApp in iOS?

Does anyone have a clue on how to create a multiline navigation/top bar in iOS? I want something similar to the status line in WhatsApp (the one that displays last seen or the current status information).
Any advice would be appreciated.
I want to achieve something like in the image (Francis Whitman / last seen [...]):
By default, a UINavigationController will use the title property of the currently-displayed view controller for the title in its navigation bar. You can have it display any arbitrary view, however, by setting the titleView property of the view controller’s navigationItem property, as so:
// In your view controller’s implementation (.m) file:
- (id)initWithNibName:(NSString *)nibName
bundle:(NSStirng *)nibBundle
{
self = [super initWithNibName:nibName bundle:nibBundle];
if (self) {
UIView *myTitleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,
0.0f,
250.0f,
44.0f)];
[myView setBackgroundColor:[UIColor greenColor]];
[[self navigationItem] setTitleView:myTitleView];
}
return self;
}
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width/2, 200)];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setTextAlignment:NSTextAlignmentCenter];
[label setNumberOfLines:0];
[label setText:_certificate.name];
self.navigationItem.titleView = label;

Resources