How to make custom right UIBarButtonItem with image and label?

I actually found this same question here but for obj.c so with that I managed to do this:

trashNavButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
        trashNavButton.addTarget(self, action: "trashItemClicked", forControlEvents: UIControlEvents.TouchUpInside)
trashNavButton = UIButton(frame: CGRectMake(0, 0, 50, 32))
trashNavButton.setTitle("(trashCount)", forState: UIControlState.Normal)
trashNavButton.setTitleColor(UIColor(red: 229.0/255.0, green: 57.0/255.0, blue: 53.0/255.0, alpha: 1.0), forState: UIControlState.Normal)
trashNavButton.titleLabel?.textAlignment = NSTextAlignment.Right
trashNavButton.setImage(UIImage(named: "trashButton"), forState: UIControlState.Normal)
rightBarButton.customView = trashNavButton
self.navigationItem.rightBarButtonItem = rightBarButton

What I’m trying to do is to have a button on the right at the navigation bar, and I want that button to also have a label on it’s left (you can see a great example on the question I mentioned above), and well this code works very well with the exception that the image is on the left and the label on the right and I want it to be the other way around, I’ll appreciate your help 🙂

Source: ios

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.