UIButton image and text spacing in iOS swift

Problem: 

I want to design my button as first image then one space followed by text.How to achieve that in swift?


Solution:

            myButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5)

            myButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0)

            myButton.setImage(myimage , for: .normal)

            myButton.setTitle("title", for: .normal)

            myButton.contentHorizontalAlignment = .fill

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift