Oleg Shamin
Oleg Shamin

Reputation: 81

Swift - How can I create button with two texts and image between them programmatically?

How can I create this button programmatically:

enter image description here

I am already tried this:

    buttonLike.setImage(UIImage(named: "imageLikeForButton"), forState: UIControlState.Normal)

    buttonLike.setTitle("Like ", forState: UIControlState.Normal)

    buttonLike.tintColor = UIColor(red: 170.0/255.0, green: 170.0/255.0, blue: 170.0/255.0, alpha: 1.0)

    buttonLike.transform = CGAffineTransformMakeScale(-1.0, 1.0)
    buttonLike.titleLabel!.transform = CGAffineTransformMakeScale(-1.0, 1.0)
    buttonLike.imageView!.transform = CGAffineTransformMakeScale(-1.0, 1.0)

But it work only for one text and one image:

enter image description here

Upvotes: 3

Views: 92

Answers (2)

ChillySean
ChillySean

Reputation: 1

You can create an UIView and put everything in this view. Then put a transparent button on the top of this view. I think this is an easier way.

Upvotes: 0

Guilherme Colares
Guilherme Colares

Reputation: 50

I think is better create a UIView and use gesturerecognizer for your actions (key pressed, etc).

Upvotes: 1

Related Questions