Reputation: 369
I'm using a UIButton as a label to display some number in its title. Every time the function is called to reset the title of this button, it flashes. It does not affect the functionality but hurts user experience. I'm wondering if there is a way to stop UIButton from this highlighting behavior?
Thanks in advance!
Edit: Following are the code where I'm simply calling a delegate method updateDigits
to refresh the button's title.
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate, DigitsEntryViewDelegate {
@IBOutlet weak var tipField1: UIButton!
@IBOutlet weak var tipField2: UIButton!
var buttonsArray = [UIButton]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tipField1.tag = 0
self.tipField2.tag = 1
self.tipField1.addTarget(self, action: "inputFieldClicked:", forControlEvents: UIControlEvents.TouchUpInside)
self.tipField2.addTarget(self, action: "inputFieldClicked:", forControlEvents: UIControlEvents.TouchUpInside)
self.buttonsArray.append(self.tipField1)
self.buttonsArray.append(self.tipField2)
}
func inputFieldClicked(sender: UIButton) {
let anchor: UIView = sender
let viewControllerForPopover = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("DigitEnter") as! DigitsEntryViewController
// set popover API values
viewControllerForPopover.currentDigitsString = sender.currentTitle
viewControllerForPopover.tagNumber = sender.tag
viewControllerForPopover.delegate = self
viewControllerForPopover.preferredContentSize = CGSizeMake(240, 320)
let popover = UIPopoverController(contentViewController:viewControllerForPopover)
popover.presentPopoverFromRect(anchor.frame, inView: anchor.superview!, permittedArrowDirections: UIPopoverArrowDirection.Down, animated: false)
}
func updateDigits(returnedDigits: String, tagNumber: Int) {
self.buttonsArray[tagNumber].setTitle(returnedDigits, forState: UIControlState.Normal)
}
}
Upvotes: 3
Views: 2268
Reputation: 5536
I could be mistaken, but the flashing looks like it may be caused by a data delivery delay; you are attempting to change the title while the new title is still being retrieved, hence the flash.
I would:
Upvotes: 1
Reputation: 38142
This should fix your issue:
[UIView performWithoutAnimation:^{
[self.myButton setTitle:text forState:UIControlStateNormal];
[self.myButton layoutIfNeeded];
}];
Upvotes: 0