For iOS7, I used the UIButton
titleLabel.frame.size.width
property to determine the width of my button title under different localisations so I could p
So we can try this code :
func withTitleAndImageAlign(title:String,image:UIImage,RL_Space:CGFloat) {
setNeedsLayout()
layoutIfNeeded()
let buttonWidth = frame.size.width
let textWidth = titleLabel?.frame.size.width
let imageWidth = imageView?.frame.size.width
let lim = buttonWidth - (textWidth! + imageWidth! + (2 * RL_Space) )
imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: lim)
titleEdgeInsets = UIEdgeInsets(top: 0, left: lim, bottom: 0, right: 0)
}