logo
down
shadow

How do I change the color of two UIButtons when I press them?


How do I change the color of two UIButtons when I press them?

By : user3099879
Date : January 11 2021, 05:14 PM
like below fixes the issue You get some methods "for free" with buttons to manage their state. One of them is isSelected. Another is the tag property, so you can figure out which button is which. Since you've only got two buttons, you can get away with just using isSelected to figure out which is which. You can also use computed vars to make your life easier. With those things in mind, here's one approach you could utilize to managing the buttons' states:
code :
@IBOutlet var firstButton: UIButton!
@IBOutlet var secondButton: UIButton!

// computed var to access your buttons
private var buttons: [UIButton] {
    return [firstButton, secondButton]
}
override func viewDidLoad() {
    super.viewDidLoad()

    // one setup to configure each button for selected or not selected
    buttons.forEach { button in
        button.setTitleColor(.darkGray,
                              for: .selected)
        button.setTitleColor(.lightGray,
                              for: .normal)
    }

    firstButton.isSelected = true
}
@IBAction func buttonAction(_ sender: UIButton) {

    UIView.animate(withDuration: 1.0) {
        // flip buttons
        self.buttons.forEach { button in
            button.isSelected.toggle()
        }

        if self.firstButton.isSelected {
            // tweak your constraints for firstButton.isSelected == true
            // tweak your constraints for secondButton.isSelected == false
        } else {
            // tweak your constraints for firstButton.isSelected == false
            // tweak your constraints for secondButton.isSelected == true
        }

    }
}


Share : facebook icon twitter icon
Is it possible to change a UIButtons background color?

Is it possible to change a UIButtons background color?


By : Abdoulaye Ndiaye
Date : March 29 2020, 07:55 AM
help you fix your problem This one has me stumped. , This can be done programmatically by making a replica:
code :
loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
[loginButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
loginButton.backgroundColor = [UIColor whiteColor];
loginButton.layer.borderColor = [UIColor blackColor].CGColor;
loginButton.layer.borderWidth = 0.5f;
loginButton.layer.cornerRadius = 10.0f;
Change Highlight Color for UIButtons

Change Highlight Color for UIButtons


By : brog1337
Date : March 29 2020, 07:55 AM
hope this fix your issue Is it possible to change the highlight color (shown when the showsTouchWhenHighlighted property is set to true) of a UIButton used in a UIToolbar? By default it's white, and since most apps use white images, it isn't the most appealing as the white highlight washes out the image. I would prefer something more like a light gray that really would highlight the image instead of preventing the user from seeing it. , To my knowledge, the answer is NO.
Change UIbuttons color after it has been created

Change UIbuttons color after it has been created


By : Carrion
Date : March 29 2020, 07:55 AM
help you fix your problem I can say that your first code version works for me, provided buttonTag's value is correct.
To debug, I suggest that you comment out the buttonTag comparison and just turn all your buttons red.
Why do my UIButtons change color in iOS 7 upon controller transition?

Why do my UIButtons change color in iOS 7 upon controller transition?


By : CrazyDolphin
Date : March 29 2020, 07:55 AM
I wish this help you You can fix this using the tintAdjustmentMode property, introduced in iOS 7:
code :
self.window.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
Two separate UIButtons sharing same press... can't press two at one time

Two separate UIButtons sharing same press... can't press two at one time


By : Roma Kiz
Date : March 29 2020, 07:55 AM
this one helps. Check that multipleTouchEnabled is true for parent views:
Related Posts Related Posts :
  • How to connect an iPhone app (rest) to XAMPP using a local WIFI connection?
  • Swift 4 delegate is not working with tabbar controller
  • How do i compile all contact's phone numbers into one cell - using CNContact
  • UIViewPropertyAnimator doesn’t work as expected
  • GoogleMaps camera target in top left corner of map iOS since pod update
  • Allowing SwiftUI to import all Contacts and delete specific ones
  • How can I obtain POST request body from WKWebView in Swift?
  • Why is array in collection view getting multiplied by amount of sections?
  • How is enumerated() constant time O(1)?
  • How to get XML data and bind in tableview in iOS Swift?
  • Interface Builder Constraints Problems
  • Xcode 11 beta can't upload app to TestFlight
  • iOS odd Thread 1: Fatal error: Index out of range on iPad
  • Cannot convert json object to struct
  • How can I prevent the stopwatch from resetting after pause
  • Cannot convert value of type '() -> _' to specified type '[UIViewController]'
  • How to make a reference to a uid stored in Firestore?
  • How do you initialize/use UITableViewCells with CellStyle = .value1 programmatically?
  • How to know if Apple has received our appeal/how long does it take Apple to respond?
  • Select new item added to SwiftUI List
  • What is the correct length: argument to provide to NSRange for NSRegularExpression using a (Swift) String?
  • I am trying to delete data from database, but sometime data is deleted and sometime data is not deleted
  • How to get slider value with subview rotation angle
  • Can't pass custom UINavigationBar / UIToolbar to UINavigationController because they don't conform to AnyClass
  • Remove app before simulator or device is lunched from Xcode
  • Auto Layout constraints for container view inside UITableView header broken for different devices
  • iPhone restarts after API call
  • What is the shortcut / How do I create function after writing it's usage in Xcode
  • Convert apple time stamp to Unix time
  • No podspec found for `React-fishhook`
  • How to test touch dialog and perform real in-app purchase?
  • Compiling Metal shaders from source on iOS 13 Simulator gives PCH error
  • conan error:I need to cross build packages for os:iOS with my Macos, but when the first package was done, it broke my cp
  • Update calendar 'start of week' from phones system calendar
  • Xcode is showing some warnings
  • How to remove the default Navigation Bar space in SwiftUI NavigiationView
  • Having trouble integrating multiple pickerviews in the same view
  • SCNNode not in SCNView hierarchy, still showing & getting touches & physics
  • How can I open my SwiftUI app and perform a function using NSUseractivity from within Siri Intent Extension?
  • NSCoding decodeObject always nil
  • Passing data in a segmented Controller?
  • Facing issue in Siri Integration with custom intents
  • ARKit3 Hardware Requirement Clarification
  • ARKit3 How to use TrueDepth camera for face tracking and face meshes of other people?
  • How to discriminate while decoding using Codable Protocol in Swift?
  • 'IPA processing failed' while distributing build in Xcode Beta
  • How to debug a crash which happened when come back from background
  • Synchronising old data with NSPersistentCloudKitContainer
  • iOS app opened from web app with url redirects to Appstore
  • How to change the color of seperator in tableView?
  • Is there a better way to watch for a key-value change?
  • How to make UIBezierPath to fill from the center
  • Why on Xcode 11, UICollectionViewCell changes size as soon as you scroll (I already set size in sizeForItem AtIndexPath:
  • How to scan non LE devices using Swift?
  • Unable to infer closure type in the current context in SwiftUI
  • What is the best way to write common code and use it entire project
  • UISegmentedControl inside UIStackView, segments text not centered - iOS 13
  • Swift & ObjC bridge - cannot find protocol declaration for "WKNavigationDelegate"
  • SwiftUI How to push to next screen when tapping on Button
  • 'NSApp' is unavailable in UIKit for Mac: How to embed Mac only framework in iOS app on macOS?
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org