ios


UIButton border color defaults to black. How can it be changed to the default ( blue ) color that is used for setting the title of the button text?


I have created a UIButton:
testNavigationButton.setTitle("Test", forState: .Normal)
testNavigationButton.layer.borderWidth = 1
I tried to change the color to:
testNavigationButton.layer.borderColor = UIColor.blueColor().CGColor
But the color of the border is different shade of blue than the default shade used for setting the title of the button. What is this shade and how can I change the color of border to this color?
You can get the color of the text using
let textColor = button.titleLabel?.textColor
And assign it to your borderColor like this:
button.layer.borderColor = textColor!.CGColor
Btw, from my test, the blue is #007aff you can initialise it using:
let color = UIColor(red: 0, green: 0.478, blue: 1, alpha: 1)
Update
class MyButton: UIButton {
private let normalColor = UIColor(red: 0, green: 0.478, blue: 1, alpha: 1)
private let highlightedColor = UIColor(red: 0, green: 0.478, blue: 1, alpha: 0.3)
override var highlighted: Bool {
willSet {
if newValue != highlighted {
let anim = CABasicAnimation(keyPath: "borderColor")
anim.fromValue = newValue ? normalColor.CGColor : highlightedColor.CGColor
anim.toValue = newValue ? highlightedColor.CGColor : normalColor.CGColor
layer.borderColor = newValue ? highlightedColor.CGColor : normalColor.CGColor
anim.duration = CATransaction.animationDuration()
anim.timingFunction = CATransaction.animationTimingFunction()
layer.addAnimation(anim, forKey: "MyButton.BorderColor")
}
}
}
}

Related Links

Insert character Just after particular character in string : Swift
App store submission error on Language/Localized
Remove line break in UIActivityViewController
How to take NSRange in swift?
UIAccessibility in gridView - doesn't see new cells
swipe to delete uitableview cell [duplicate]
Changing Label Text & Colour Depending On Current Time
Ionic 2 cordova-plugin-mauron85-background-geolocation Not Updating UI
NSURLSession error when uploading on WiFi: NSURLErrorDomain Code=-999
iOS Observe absolute scale on CALayer in hierarchy
iOS adjust UICollectionView Insets after hiding Navigation Bar
Check if phone is face down
IBOutlets getting nil when dismissing viewController
Cant find Accella Mobile SDK IOS
How to create a custom UISlider
how to dismiss a UIView when tapped outside its bounds?

Categories

HOME
sbt
uwp
validation
graph
dynamic-programming
dicom
android-activity
outlook
fonts
genetic-algorithm
svg.js
spi
spacemacs
google-analytics-api
google-adwords
regression
autofac
telnet
pie-chart
bluej
openmodelica
nservicebus
union
jscrollpane
postgresql-9.5
eigen3
html-email
cmusphinx
abaqus
curve-fitting
pydev
multiprocessing
mlr
selenium-edgedriver
precision
mathdotnet
yii1.x
esri
feedly
opensuse
instance
scatter-plot
dlopen
machine-language
server-sent-events
sieve-of-eratosthenes
titanium-alloy
folly
response
symfony-process
firedac
dxgi
simplesamlphp
adal.js
multisite
dump
column-oriented
lapply
android-sdk-tools
business-logic
facebook-audience-network
heritrix
webpagetest
jstorm
uploadify
jca
storage-duration
autopy
ironmq
tun
session-replication
tabbar
realm-list
gem5
cordova-cli
zim-database
declaration
android-design-library
jet.com-apis
catalina.out
asf
globus-toolkit
grunt-contrib-copy
modalpopupextender
validform
jquery-mobile-popup
blueprint
simpleaudioengine
xcode4.2
guice-servlet
html5-apps
hudson-plugins
java-ee-5
cocosbuilder
f2c
duplicate-data
datatemplate
etrade-api
noaa
scramble
geneva-framework
clipboard-pictures
stsadm

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App