Swift----封装自定义View控件

封装自定义View控件, 以图+文字+图的方式

声明
import UIKit
import TangramKit

class SettingView: TGRelativeLayout {
    init() {
        super.init(frame: CGRect.zero)
        innerInit()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        innerInit()
    }
    
    func innerInit() {
        tg_width.equal(.fill)
        tg_height.equal(55)
        
        backgroundColor = .white
        addSubview(iconView)
        addSubview(titleView)
        addSubview(moreIconView)
    }
    
    /// 左侧图标
    lazy var iconView: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "Setting")
        
        result.tg_width.equal(20)
        result.tg_height.equal(20)
        result.tg_centerY.equal(0)
        result.tg_leading.equal(16)
        return result
    }()
    
    /// 标题
    lazy var titleView: UILabel = {
        let result = UILabel()
        result.text = "设置"
        result.tg_width.equal(.wrap)
        result.tg_height.equal(.wrap)
        result.tg_centerY.equal(0)
        result.tg_leading.equal(iconView.tg_trailing).offset(16)
        return result
    }()

    /// 右侧图标
    lazy var moreIconView: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "Arrow")
        result.tg_width.equal(20)
        result.tg_height.equal(20)
        result.tg_centerY.equal(0)
        result.tg_right.equal(16)
        return result
    }()
}
使用
let container = TGLinearLayout(.vert)
container.tg_width.equal(.fill)
container.tg_height.equal(.wrap)
container.tg_top.equal(TGLayoutPos.tg_safeAreaMargin).offset(16)
container.tg_space = 1

container.addSubview(settingView)
container.addSubview(collectView)

view.addSubview(container)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值