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 to detect if the device has just been rebooted?
iOS SSL Connection in Swift
Video playback on cube Webgl / Three.js IOS
How do I dismiss the AVPlayer automatically when playback has completed?
Multiple rows in tableview reacts to one action intended for the subview of one row
How to design a view that's a UIScrollView that contains multiple labels and a UITextView that can dynamically adjust its height to text
Firebase Cloud Message service api call show message in logs but not in pop up
App crashing after trying to load 10 webpages with UIWebView
iOS 10 Beta Not Working With Xcode 7.3.1
Stack size isn't correct after constraint
Custom UIPageControl with dot images
Getting error code ('wht?') in ExtAudioFileOpenURL in Swift when using aubio to read file
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?

Categories

HOME
ssl
hadoop
f#
printing
redirect
azure-search
apt-get
graylog2
rtmp
applet
geolocation
chronicle
antlr
identifier
pouchdb
highlight
numericupdown
scale
git-svn
round-robin
amplitude
durandal-2.0
jscodeshift
dsc
cadvisor
scalability
android-button
android-security
scom
svgpanzoom
dokuwiki
tweenmax
server-sent-events
bits
joe-editor
dsx
ibm-wcm
mindstorms
mamp-pro
integer-programming
freecodecamp
oracle-aq
strip-tags
infiniband
view-source
manual
column-oriented
kie-workbench
sqlite-net
informatica-cloud
tealeaf
xpdf
ellipsis
pypyodbc
okuma
illegalstateexception
ane
uat
nominatim
quasar
session-replication
polygons
protected
xsb
selectsinglenode
translucency
bloodhound
alienvault
javaw
office-2010
batman.js
showcaseview
shift
northwind
mysql-backup
ramaze
apache-config
regexbuddy
queryanalyzer
iphone-sdk-3.1
development-machine

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