设置UIButton内图文位置

 UIButton图片位置

```

// TitleButton.swift

import UIKit

class TitleButton: UIButton {

override init(frame: CGRect) {

super.init(frame: frame)

setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)

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

setImage(UIImage(named: "navigationbar_arrow_up"), forState: UIControlState.Highlighted)

sizeToFit()

}

required init?(coder aDecoder: NSCoder) {

fatalError("init(coder:) has not been implemented")

}

/**

这个方法里调整布局

*/

override func layoutSubviews() {

super.layoutSubviews()

titleLabel?.frame.origin.x = 0

imageView?.frame.origin.x = titleLabel!.frame.size.width

}

}

```

你可能感兴趣的:(设置UIButton内图文位置)