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

UITextViewDelegate in non viewcontroller class
How can I get indexPath of a uiview on a cell - iOS
How to allow audio to continue to play when app is backgrounded?
How to limit the pulling distance with a refresh control?
Image fits into UICollectionView Cell
Caching the downloaded data
Core Location and Google Maps
(Objective C) NSDate is nil to convert a date in String
Swift need to reload TableView that is contained within a containerView
Remove iAds from SKScene
Adjust UICollectionView Size Dynamically to Ensure No Inter Item Spacing
How to replace Detail in UISplitViewController in Swift?
Adding Delay In A For Loop Without Blocking UI
Swift 1/2 UITextView suggestion by tag “#” or “#”
UICollectionViewController that looks like UITableViewController
iPhone simulator screenshot is not in proper dimension

Categories

HOME
selenium
bootstrap-4
coffeescript
varnish
servlets
tcl
android-wear
datetime
twitter-digits
xquery
robot
wikipedia-api
windows-server-2012-r2
predictionio
h2o
calayer
oracle-ucm
executable
w3.css
graph-tool
coreos
google-cloud-sdk
plots.jl
partitioning
spring-cloud-consul
vast
formio
nested-set-model
selenium-edgedriver
abstract-syntax-tree
stylesheet
regex-group
temp
shinydashboard
instance
angular2-databinding
svgpanzoom
zipline
caldroid
windows-scripting
httpexception
wrk
jquery-masonry
formstack
database-cleaner
canopen
getelementbyid
wxhaskell
mysql-notifier
error-correction
bootstrap-slider
olingo
turnjs
statistics-bootstrap
cglib
insert-update
dms
benerator
docklight
occam-pi
linqtocsv
ssha
aldryn
text-alignment
biojava
double-quotes
telescope
maven-cargo
gem5
simperium
android-print-framework
data-science-studio
twitter-follow
reactive-cocoa-3
tab-delimited
repaint
before-save
dojo.gridx
short
nine-patch
jquery-backstretch
azimuth
libtorrent-rasterbar
ioerror
apache-commons-dbcp
sparc
nsmanagedobjectmodel
hogan.js
clean-urls
timestamp-with-timezone
hiphop
teamcity-7.0
intel-8080
gemstone
jtemplates
android-3.1
renderaction
arraycopy
webshop
geneva-framework
shareware
corporate-policy

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