美文网首页
设置UIButton内图文位置

设置UIButton内图文位置

作者: 阴中阳 | 来源:发表于2016-12-17 14:46 被阅读19次

 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内图文位置

      本文链接:https://www.haomeiwen.com/subject/dzqsyttx.html