How to change border thickness of UISearchBar?How to change the name of an iOS app?Can I embed a custom font in an iPhone application?How to implement UISearchBar with no borderUISearchBar Appearance still shows 1px border when pulled downChanging navigation bar color in SwiftChange tab bar item selected color in a storyboardRemove border between View and Search BarHow to set Status Bar Style in Swift 3iOS UISearchBar remove faint lines in Swift 3iOS 11 UISearchBar in UINavigationBar
Interpretation of non-significant results as "trends"
Why do airports remove/realign runways?
Gaining Proficiency in Vehicles (water)
How was the website able to tell my credit card was wrong before it processed it?
How to use Adostop Eco stop bath?
How should I ask for a "pint" in countries that use metric?
What does "spinning upon the shoals" mean?
How to "extend" classes in Haskell
How does one acquire an undead eyeball encased in a gem?
What are the effects of abstaining from eating a certain flavor?
How do I talk to my wife about unrealistic expectations?
Deck of Cards with Shuffle and Sort functionality
How do I use my adapted PS2 keyboard & mouse on a windows 10 computer?
Wires do not connect in Circuitikz
Computer name naming convention for security
Is this car delivery via Ebay Motors on Craigslist a scam?
How to execute a program from terminal redirecting stdout and stderr to systemd's journal?
Other Space Shuttle O-ring failures
aligning diagram with arrows
What was the nature of the known bugs in the Space Shuttle software?
Tesco's Burger Relish Best Before End date number
How do I explain that I don't want to maintain old projects?
is there a real life meaning about KMeans error?
Four ships at the ocean with the same distance
How to change border thickness of UISearchBar?
How to change the name of an iOS app?Can I embed a custom font in an iPhone application?How to implement UISearchBar with no borderUISearchBar Appearance still shows 1px border when pulled downChanging navigation bar color in SwiftChange tab bar item selected color in a storyboardRemove border between View and Search BarHow to set Status Bar Style in Swift 3iOS UISearchBar remove faint lines in Swift 3iOS 11 UISearchBar in UINavigationBar
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to make my search bar look like this
A white background with a thin grey border.
On Xcode, I can set Search style
to default (which gives the white background) and Bar tint
to grey (which gives the grey border.)
But the result I get is this
How do I change the thickness of the bar to reflect the design I'm going for?
(also, is there a way to change just the font of the search bar? I only found ways to change the font size)
ios swift xcode uisearchbar
add a comment |
I'm trying to make my search bar look like this
A white background with a thin grey border.
On Xcode, I can set Search style
to default (which gives the white background) and Bar tint
to grey (which gives the grey border.)
But the result I get is this
How do I change the thickness of the bar to reflect the design I'm going for?
(also, is there a way to change just the font of the search bar? I only found ways to change the font size)
ios swift xcode uisearchbar
What you want is probably a combination ofsetBackgroundImage(_:for:barMetrics:)
andsetSearchFieldBackgroundImage(_:for:)
. Have you tried that?
– matt
Mar 25 at 22:35
Isn't that to set the background image? I'm just trying to change the thickness of the bar
– Richard Reis
Mar 25 at 22:53
@matt what size of images you prefer for SearchBar?
– Parth Patel
Mar 26 at 4:51
use the style minimal and set the translucent true
– Sanad Barjawi
Mar 26 at 7:46
add a comment |
I'm trying to make my search bar look like this
A white background with a thin grey border.
On Xcode, I can set Search style
to default (which gives the white background) and Bar tint
to grey (which gives the grey border.)
But the result I get is this
How do I change the thickness of the bar to reflect the design I'm going for?
(also, is there a way to change just the font of the search bar? I only found ways to change the font size)
ios swift xcode uisearchbar
I'm trying to make my search bar look like this
A white background with a thin grey border.
On Xcode, I can set Search style
to default (which gives the white background) and Bar tint
to grey (which gives the grey border.)
But the result I get is this
How do I change the thickness of the bar to reflect the design I'm going for?
(also, is there a way to change just the font of the search bar? I only found ways to change the font size)
ios swift xcode uisearchbar
ios swift xcode uisearchbar
asked Mar 25 at 22:29
Richard ReisRichard Reis
547 bronze badges
547 bronze badges
What you want is probably a combination ofsetBackgroundImage(_:for:barMetrics:)
andsetSearchFieldBackgroundImage(_:for:)
. Have you tried that?
– matt
Mar 25 at 22:35
Isn't that to set the background image? I'm just trying to change the thickness of the bar
– Richard Reis
Mar 25 at 22:53
@matt what size of images you prefer for SearchBar?
– Parth Patel
Mar 26 at 4:51
use the style minimal and set the translucent true
– Sanad Barjawi
Mar 26 at 7:46
add a comment |
What you want is probably a combination ofsetBackgroundImage(_:for:barMetrics:)
andsetSearchFieldBackgroundImage(_:for:)
. Have you tried that?
– matt
Mar 25 at 22:35
Isn't that to set the background image? I'm just trying to change the thickness of the bar
– Richard Reis
Mar 25 at 22:53
@matt what size of images you prefer for SearchBar?
– Parth Patel
Mar 26 at 4:51
use the style minimal and set the translucent true
– Sanad Barjawi
Mar 26 at 7:46
What you want is probably a combination of
setBackgroundImage(_:for:barMetrics:)
and setSearchFieldBackgroundImage(_:for:)
. Have you tried that?– matt
Mar 25 at 22:35
What you want is probably a combination of
setBackgroundImage(_:for:barMetrics:)
and setSearchFieldBackgroundImage(_:for:)
. Have you tried that?– matt
Mar 25 at 22:35
Isn't that to set the background image? I'm just trying to change the thickness of the bar
– Richard Reis
Mar 25 at 22:53
Isn't that to set the background image? I'm just trying to change the thickness of the bar
– Richard Reis
Mar 25 at 22:53
@matt what size of images you prefer for SearchBar?
– Parth Patel
Mar 26 at 4:51
@matt what size of images you prefer for SearchBar?
– Parth Patel
Mar 26 at 4:51
use the style minimal and set the translucent true
– Sanad Barjawi
Mar 26 at 7:46
use the style minimal and set the translucent true
– Sanad Barjawi
Mar 26 at 7:46
add a comment |
2 Answers
2
active
oldest
votes
Follow this below steps -
1.Choose UITextField
from the object library
2.Drag to your storyboard
3.Choose border style as none
.
4.Create a Swift file and add this below extension -
extension UIView
@IBInspectable var cornerRadius: CGFloat
get
return layer.cornerRadius
set
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
@IBInspectable var borderWidth: CGFloat
get
return layer.borderWidth
set
layer.borderWidth = newValue
@IBInspectable var borderColor: UIColor?
get
return UIColor(cgColor: layer.borderColor!)
set
layer.borderColor = newValue?.cgColor
extension UIButton
func roundedButton()
let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.topLeft , .topRight],
cornerRadii:CGSize(width:8.0, height:8.0))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = self.bounds
maskLayer1.path = maskPAth1.cgPath
self.layer.mask = maskLayer1
extension UITextField
func setLeftPaddingPoints(_ amount:CGFloat)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.leftView = paddingView
self.leftViewMode = .always
func setRightPaddingPoints(_ amount:CGFloat)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.rightView = paddingView
self.rightViewMode = .always
extension UITextField
@IBInspectable var maxLength: Int
get
if let length = objc_getAssociatedObject(self, &kAssociationKeyMaxLength) as? Int
return length
else
return Int.max
set
objc_setAssociatedObject(self, &kAssociationKeyMaxLength, newValue, .OBJC_ASSOCIATION_RETAIN)
addTarget(self, action: #selector(checkMaxLength), for: .editingChanged)
@objc func checkMaxLength(textField: UITextField)
guard let prospectiveText = self.text,
prospectiveText.count > maxLength
else
return
let selection = selectedTextRange
let indexEndOfText = prospectiveText.index(prospectiveText.startIndex, offsetBy: maxLength)
let substring = prospectiveText[..<indexEndOfText]
text = String(substring)
selectedTextRange = selection
5.Now you can access this extensions either from storyboard or from code to change the values and see the effects.
6.You can change the corner radius, border width, border colour for UITextField
.
Hope this method also helps.
works for me :)
– Sukhwinder Singh
Apr 9 at 5:59
add a comment |
The style UISearchBar.Style.minimal provides no default background color or image
and use UITextFiled instead search bar so you can customise icon location
YourTextFiled.rightView = UIImageView(image: UIImage(named: "search-icon"))
YourTextFiled.rightViewMode = UITextField.ViewMode.always
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347314%2fhow-to-change-border-thickness-of-uisearchbar%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Follow this below steps -
1.Choose UITextField
from the object library
2.Drag to your storyboard
3.Choose border style as none
.
4.Create a Swift file and add this below extension -
extension UIView
@IBInspectable var cornerRadius: CGFloat
get
return layer.cornerRadius
set
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
@IBInspectable var borderWidth: CGFloat
get
return layer.borderWidth
set
layer.borderWidth = newValue
@IBInspectable var borderColor: UIColor?
get
return UIColor(cgColor: layer.borderColor!)
set
layer.borderColor = newValue?.cgColor
extension UIButton
func roundedButton()
let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.topLeft , .topRight],
cornerRadii:CGSize(width:8.0, height:8.0))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = self.bounds
maskLayer1.path = maskPAth1.cgPath
self.layer.mask = maskLayer1
extension UITextField
func setLeftPaddingPoints(_ amount:CGFloat)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.leftView = paddingView
self.leftViewMode = .always
func setRightPaddingPoints(_ amount:CGFloat)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.rightView = paddingView
self.rightViewMode = .always
extension UITextField
@IBInspectable var maxLength: Int
get
if let length = objc_getAssociatedObject(self, &kAssociationKeyMaxLength) as? Int
return length
else
return Int.max
set
objc_setAssociatedObject(self, &kAssociationKeyMaxLength, newValue, .OBJC_ASSOCIATION_RETAIN)
addTarget(self, action: #selector(checkMaxLength), for: .editingChanged)
@objc func checkMaxLength(textField: UITextField)
guard let prospectiveText = self.text,
prospectiveText.count > maxLength
else
return
let selection = selectedTextRange
let indexEndOfText = prospectiveText.index(prospectiveText.startIndex, offsetBy: maxLength)
let substring = prospectiveText[..<indexEndOfText]
text = String(substring)
selectedTextRange = selection
5.Now you can access this extensions either from storyboard or from code to change the values and see the effects.
6.You can change the corner radius, border width, border colour for UITextField
.
Hope this method also helps.
works for me :)
– Sukhwinder Singh
Apr 9 at 5:59
add a comment |
Follow this below steps -
1.Choose UITextField
from the object library
2.Drag to your storyboard
3.Choose border style as none
.
4.Create a Swift file and add this below extension -
extension UIView
@IBInspectable var cornerRadius: CGFloat
get
return layer.cornerRadius
set
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
@IBInspectable var borderWidth: CGFloat
get
return layer.borderWidth
set
layer.borderWidth = newValue
@IBInspectable var borderColor: UIColor?
get
return UIColor(cgColor: layer.borderColor!)
set
layer.borderColor = newValue?.cgColor
extension UIButton
func roundedButton()
let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.topLeft , .topRight],
cornerRadii:CGSize(width:8.0, height:8.0))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = self.bounds
maskLayer1.path = maskPAth1.cgPath
self.layer.mask = maskLayer1
extension UITextField
func setLeftPaddingPoints(_ amount:CGFloat)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.leftView = paddingView
self.leftViewMode = .always
func setRightPaddingPoints(_ amount:CGFloat)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.rightView = paddingView
self.rightViewMode = .always
extension UITextField
@IBInspectable var maxLength: Int
get
if let length = objc_getAssociatedObject(self, &kAssociationKeyMaxLength) as? Int
return length
else
return Int.max
set
objc_setAssociatedObject(self, &kAssociationKeyMaxLength, newValue, .OBJC_ASSOCIATION_RETAIN)
addTarget(self, action: #selector(checkMaxLength), for: .editingChanged)
@objc func checkMaxLength(textField: UITextField)
guard let prospectiveText = self.text,
prospectiveText.count > maxLength
else
return
let selection = selectedTextRange
let indexEndOfText = prospectiveText.index(prospectiveText.startIndex, offsetBy: maxLength)
let substring = prospectiveText[..<indexEndOfText]
text = String(substring)
selectedTextRange = selection
5.Now you can access this extensions either from storyboard or from code to change the values and see the effects.
6.You can change the corner radius, border width, border colour for UITextField
.
Hope this method also helps.
works for me :)
– Sukhwinder Singh
Apr 9 at 5:59
add a comment |
Follow this below steps -
1.Choose UITextField
from the object library
2.Drag to your storyboard
3.Choose border style as none
.
4.Create a Swift file and add this below extension -
extension UIView
@IBInspectable var cornerRadius: CGFloat
get
return layer.cornerRadius
set
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
@IBInspectable var borderWidth: CGFloat
get
return layer.borderWidth
set
layer.borderWidth = newValue
@IBInspectable var borderColor: UIColor?
get
return UIColor(cgColor: layer.borderColor!)
set
layer.borderColor = newValue?.cgColor
extension UIButton
func roundedButton()
let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.topLeft , .topRight],
cornerRadii:CGSize(width:8.0, height:8.0))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = self.bounds
maskLayer1.path = maskPAth1.cgPath
self.layer.mask = maskLayer1
extension UITextField
func setLeftPaddingPoints(_ amount:CGFloat)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.leftView = paddingView
self.leftViewMode = .always
func setRightPaddingPoints(_ amount:CGFloat)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.rightView = paddingView
self.rightViewMode = .always
extension UITextField
@IBInspectable var maxLength: Int
get
if let length = objc_getAssociatedObject(self, &kAssociationKeyMaxLength) as? Int
return length
else
return Int.max
set
objc_setAssociatedObject(self, &kAssociationKeyMaxLength, newValue, .OBJC_ASSOCIATION_RETAIN)
addTarget(self, action: #selector(checkMaxLength), for: .editingChanged)
@objc func checkMaxLength(textField: UITextField)
guard let prospectiveText = self.text,
prospectiveText.count > maxLength
else
return
let selection = selectedTextRange
let indexEndOfText = prospectiveText.index(prospectiveText.startIndex, offsetBy: maxLength)
let substring = prospectiveText[..<indexEndOfText]
text = String(substring)
selectedTextRange = selection
5.Now you can access this extensions either from storyboard or from code to change the values and see the effects.
6.You can change the corner radius, border width, border colour for UITextField
.
Hope this method also helps.
Follow this below steps -
1.Choose UITextField
from the object library
2.Drag to your storyboard
3.Choose border style as none
.
4.Create a Swift file and add this below extension -
extension UIView
@IBInspectable var cornerRadius: CGFloat
get
return layer.cornerRadius
set
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
@IBInspectable var borderWidth: CGFloat
get
return layer.borderWidth
set
layer.borderWidth = newValue
@IBInspectable var borderColor: UIColor?
get
return UIColor(cgColor: layer.borderColor!)
set
layer.borderColor = newValue?.cgColor
extension UIButton
func roundedButton()
let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.topLeft , .topRight],
cornerRadii:CGSize(width:8.0, height:8.0))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = self.bounds
maskLayer1.path = maskPAth1.cgPath
self.layer.mask = maskLayer1
extension UITextField
func setLeftPaddingPoints(_ amount:CGFloat)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.leftView = paddingView
self.leftViewMode = .always
func setRightPaddingPoints(_ amount:CGFloat)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.rightView = paddingView
self.rightViewMode = .always
extension UITextField
@IBInspectable var maxLength: Int
get
if let length = objc_getAssociatedObject(self, &kAssociationKeyMaxLength) as? Int
return length
else
return Int.max
set
objc_setAssociatedObject(self, &kAssociationKeyMaxLength, newValue, .OBJC_ASSOCIATION_RETAIN)
addTarget(self, action: #selector(checkMaxLength), for: .editingChanged)
@objc func checkMaxLength(textField: UITextField)
guard let prospectiveText = self.text,
prospectiveText.count > maxLength
else
return
let selection = selectedTextRange
let indexEndOfText = prospectiveText.index(prospectiveText.startIndex, offsetBy: maxLength)
let substring = prospectiveText[..<indexEndOfText]
text = String(substring)
selectedTextRange = selection
5.Now you can access this extensions either from storyboard or from code to change the values and see the effects.
6.You can change the corner radius, border width, border colour for UITextField
.
Hope this method also helps.
edited Mar 26 at 6:52
onCompletion
4,3043 gold badges22 silver badges31 bronze badges
4,3043 gold badges22 silver badges31 bronze badges
answered Mar 26 at 6:33
Gurpreet SinghGurpreet Singh
212 bronze badges
212 bronze badges
works for me :)
– Sukhwinder Singh
Apr 9 at 5:59
add a comment |
works for me :)
– Sukhwinder Singh
Apr 9 at 5:59
works for me :)
– Sukhwinder Singh
Apr 9 at 5:59
works for me :)
– Sukhwinder Singh
Apr 9 at 5:59
add a comment |
The style UISearchBar.Style.minimal provides no default background color or image
and use UITextFiled instead search bar so you can customise icon location
YourTextFiled.rightView = UIImageView(image: UIImage(named: "search-icon"))
YourTextFiled.rightViewMode = UITextField.ViewMode.always
add a comment |
The style UISearchBar.Style.minimal provides no default background color or image
and use UITextFiled instead search bar so you can customise icon location
YourTextFiled.rightView = UIImageView(image: UIImage(named: "search-icon"))
YourTextFiled.rightViewMode = UITextField.ViewMode.always
add a comment |
The style UISearchBar.Style.minimal provides no default background color or image
and use UITextFiled instead search bar so you can customise icon location
YourTextFiled.rightView = UIImageView(image: UIImage(named: "search-icon"))
YourTextFiled.rightViewMode = UITextField.ViewMode.always
The style UISearchBar.Style.minimal provides no default background color or image
and use UITextFiled instead search bar so you can customise icon location
YourTextFiled.rightView = UIImageView(image: UIImage(named: "search-icon"))
YourTextFiled.rightViewMode = UITextField.ViewMode.always
answered Mar 26 at 7:38
TejaswiniTejaswini
11 bronze badge
11 bronze badge
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347314%2fhow-to-change-border-thickness-of-uisearchbar%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What you want is probably a combination of
setBackgroundImage(_:for:barMetrics:)
andsetSearchFieldBackgroundImage(_:for:)
. Have you tried that?– matt
Mar 25 at 22:35
Isn't that to set the background image? I'm just trying to change the thickness of the bar
– Richard Reis
Mar 25 at 22:53
@matt what size of images you prefer for SearchBar?
– Parth Patel
Mar 26 at 4:51
use the style minimal and set the translucent true
– Sanad Barjawi
Mar 26 at 7:46