ios


How to avoid text color to change on UIButton selection with selectors on UIControlEvents?


How to avoid text color to change on UIButton selection with selectors on UIControlEvents ?
I am trying to make sure that the text color of my button doesn't change when it's higlighted, selected or normal. Because of my selector, it is not working. I have also tried changing the titleLabel's text color in the selectors but it didn't work. As you can see I need to change the backgroundcolor when it's highlited... Adding control events target is the only way I found to change the background color on selection.
Here is my button configuration code :
func setBtn(btn: UIButton) {
setBtnTarget(btn)
btn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
btn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Highlighted )
btn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Selected)
}
func setBtnTarget(btn: UIButton) {
btn.addTarget(self, action: "highlighted:", forControlEvents: UIControlEvents.TouchDown)
btn.addTarget(self, action: "normal:", forControlEvents: UIControlEvents.TouchUpInside)
}
func highlighted(btn : UIButton) {
btn.backgroundColor = UIColor(red:0, green:0.133, blue:0.229, alpha:1)
}
func normal(btn : UIButton) {
btn.backgroundColor = UIColor(red:0, green:0.058, blue:0.099, alpha:1)
}
Any other working alternatives are welcome. Thanks in advance.
This seems good, you just need to make sure that your button type is custom.
let btn = UIButton(type: .Custom)

Related Links

How passing data with multiple prepareforsegue in a uitableviewcell swift
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

Categories

HOME
opencv
asp.net-identity
sqlite
office-js
collections
image-segmentation
prometheus
logback
sony
eloqua
higher-order-functions
editor
plots.jl
prerender
teraterm
revitpythonshell
rgdal
padding
ollydbg
server-sent-events
capstone
solid-principles
easy-digital-downloads
textangular
android-studio-2.1
strip-tags
arm7
android-gps
ternary
canopen
mspgcc
abbyy
fasta
manual
javascript-security
hipi
bosh-deployer
setwindowshookex
ubuntu-15.04
jsbin
rsh
qlpreviewcontroller
securesocial
bash-completion
uiswitch
balana
jni4net
actioncable
xirr
folder-structure
biojava
telescope
equinox
keypad
cordova-cli
swift-array
reactive-cocoa-3
scribe
isql
gnat
dynamic-data-display
syndication-feed
jquery-backstretch
dirpagination
b2b
xsltforms
jqgrid-php
lightstreamer
notifyicon
dfsort
scala-pickling
deap
transport-stream
emacs-jedi
wow64
tempo
nspersistentdocument
word-2010
wpf-4.0
timespan
xsocket
harvest
working-directory
xml-dtd
tipsy
settings.bundle
closest
textboxlist
ssao
xmltextwriter
openfeint
android-3.1
mkmapviewdelegate
webshop
resharper-4.5
variable-names
metaphone

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