Question

In iOS 6 and xcode 4, I had this: https://dl.dropboxusercontent.com/u/60718318/photo.PNG which was easily created with the code

[editButton setTintColor:[UIColor theGreenColor];

But on an iOS 7 phone, with the app built with the iOS 6 SDK using xcode 5, the edit button becomes un-tinted using this same exact code. (I can only post two images maximum, so just imagine that the edit button is the same color as the back button) Many people both here on SO and all over the internet say that the only way to tint buttons now is to call

self.navigationController.navigationBar.tintColor = [UIColor theGreenColor];

which is also referenced in WWDC sessions. However, when I try something like this, I just get the following: https://dl.dropboxusercontent.com/u/60718318/photo-2.PNG which is not even close to correct. And according to the WWDC session I watched, this is supposed to tint BOTH buttons rather than just 1. How can I just tint 1 button, like I could in iOS 6 in xcode 4?

Was it helpful?

Solution

I don't think this is even possible anymore, I honestly think Apple just completely removed the functionality for no reason and without actually mentioning that they did. If anyone ever sees this question and wonders how I bypassed it, I just took a picture of the old button and used it as the image for the new button.

OTHER TIPS

Thats certainly very unusual since you definitely can provide said functionality. The trick is to modify the tintColor of the UIBarButtonItem's UIButton rather than directly onto the item. Heres a naive implementation of a ViewController implementing this

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.rightBarButtonItem = createBarButtonItem()
    }

    func createBarButtonItem() -> UIBarButtonItem {
        let button = UIButton(frame: CGRect(origin: CGPointZero, size: CGSize(width: 44, height: 44)))
        button.setTitle("Press Me", forState: .Normal)
        button.addTarget(self, action: "handleButtonTap:", forControlEvents: .TouchUpInside)
        button.tintColor = UIColor.blueColor()
        let buttonItem = UIBarButtonItem(customView: button)
        return buttonItem
    }

    func handleButtonTap(button: UIButton) {
        button.tintColor = UIColor.redColor()
    }
}

Naturally you would want to manage the state of the buttons selection so you can toggle the color, but I leave that up to you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top