//
// 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
}
}
2.使用
let titleBtn = TitleButton()
本文详细介绍了如何使用Swift编程语言结合UI框架创建自定义按钮组件,包括按钮的样式设置、状态变化处理以及响应式布局调整。通过实例演示了不同状态下的图片切换和颜色改变,展示了Swift UI在构建用户交互界面时的灵活性和简洁性。
5066

被折叠的 条评论
为什么被折叠?



