How to Change Searchbar Border Color

How to change SearchBar border color

Result of the code below.

self.searchBar.searchBar.searchBarStyle = UISearchBarStyle.Prominent
self.searchBar.searchBar.translucent = false
let textFieldInsideSearchBar = self.searchBar.searchBar.valueForKey("searchField") as? UITextField
textFieldInsideSearchBar?.backgroundColor = UIColor.whiteColor()
self.searchBar.searchBar.barTintColor = UIColor.whiteColor()

Code above will give you all white searchbar but likely there will be black lines at top and bottom of the searchbar as you can see from the attachment. If you see the black lines and if you don't want them, change;

self.searchBar.searchBar.barTintColor = UIColor.whiteColor()

with

self.searchBar.searchBar.backgroundImage = UIImage(named: "nameOfYourWhiteImage")

And you will have a clean white searchbar. Hope this solves your problem. Good luck!

How to change border and icons in Search bar (Swift)

To add borders use the views layer property.

self.searchBar.layer.borderColor = UIColor.blueColor().CGColor
self.searchBar.layer.borderWidth = 1

If you want to add the corner radius to the searchBar:

self.searchBar.layer.cornerRadius = 3.0
self.searchBar.clipsToBounds = true

To change the searchIcon call the following method on the searchbar:

self.searchbar.setImage(image, icon: UISearchBarIcon. UISearchBarIcon.Search, state: UIControlState.Normal)

To change the cross:

self.searchbar.setImage(image, icon: UISearchBarIcon. UISearchBarIcon.Clear, state: UIControlState.Normal)

How to add a 1 pixel gray border around a UISearchBar TextField

Try this code:

//First add the following import and macro:
#import <QuartzCore/QuartzCore.h>
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

//Then change yourSearchBar border:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
for (id object in [[[yourSearchBar subviews] objectAtIndex:0] subviews])
{
if ([object isKindOfClass:[UITextField class]])
{
UITextField *textFieldObject = (UITextField *)object;
textFieldObject.layer.borderColor = [[UIColor grayColor] CGColor];
textFieldObject.layer.borderWidth = 1.0;
break;
}
}
}
else
{
for (id object in [yourSearchBar subviews])
{
if ([object isKindOfClass:[UITextField class]])
{
UITextField *textFieldObject = (UITextField *)object;
textFieldObject.layer.borderColor = [[UIColor grayColor] CGColor];
textFieldObject.layer.borderWidth = 1.0;
break;
}
}
}

Why does this search bar have this weird outline? - CSS

Because border add default border-color & width

.search-bar {
border: 0;
outline: 0;
}

How do I create a search Bar with outline Border in AppBar in Flutter?

You can do this by using a TextField and styling it according to your needs.

Inside AppBar, I've used a Row for the title parameter. Inside that Row, I have the title text and the searchbar textfield.

Code:

appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text("Flutter Demo"),
const SizedBox(
width: 120,
), // SizedBox
Expanded(
child: TextField(
decoration: InputDecoration(
filled: true,
fillColor: const Color(0xFFFFFFFF),
isDense: true,
contentPadding: const EdgeInsets.symmetric(horizontal: 15.0),
/* -- Text and Icon -- */
hintText: "Search Products...",
hintStyle: const TextStyle(
fontSize: 18,
color: Color(0xFFB3B1B1),
), // TextStyle
suffixIcon: const Icon(
Icons.search,
size: 26,
color: Colors.black54,
), // Icon
/* -- Border Styling -- */
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(45.0),
borderSide: const BorderSide(
width: 2.0,
color: Color(0xFFFF0000),
), // BorderSide
), // OutlineInputBorder
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(45.0),
borderSide: const BorderSide(
width: 2.0,
color: Colors.grey,
), // BorderSide
), // OutlineInputBorder
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(45.0),
borderSide: const BorderSide(
width: 2.0,
color: Colors.grey,
), // BorderSide
), // OutlineInputBorder
), // InputDecoration
), // TextField
), // Expanded
],
), // Row
), // Appbar

You can style it further according to your application.

Image:

Screenshot

How to change the color of Searchbar

I needed to use this instead:

background-color: transparent;


Related Topics



Leave a reply



Submit