欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 金融 > 封装常用控制器

封装常用控制器

2025/6/17 0:34:15 来源:https://blog.csdn.net/Unlimited_ci/article/details/145422268  浏览:    关键词:封装常用控制器

封装常用控制器

在这里插入图片描述

//
//  BaseLogicController.swift
//  项目中通用的逻辑控制器import UIKit
import TangramKitclass BaseLogicController: BaseCommonController {/// 根容器var rootContainer:TGBaseLayout!/// 头部容器var superHeaderContainer:TGBaseLayout!var superHeaderContentContainer:TGBaseLayout!/// 底部容器var superFooterContainer:TGBaseLayout!var superFooterContentContainer:TGBaseLayout!/// 容器var container:TGBaseLayout!/// 初始化RelativeLayout容器,四边都在安全区内func initRelativeLayoutSafeArea() {initLinearLayout()//headerinitHeaderContainer()container = TGRelativeLayout()container.tg_width.equal(.fill)container.tg_height.equal(.fill)container.backgroundColor = .clearrootContainer.addSubview(container)initFooterContainer()}/// 初始化垂直方向LinearLayout容器,四边都在安全区内func initLinearLayoutSafeArea() {initLinearLayout()//headerinitHeaderContainer()//frameframeContainer=TGRelativeLayout();frameContainer.tg_width.equal(.fill)frameContainer.tg_height.equal(.fill)frameContainer.backgroundColor = .clearrootContainer.addSubview(frameContainer)container = TGLinearLayout(.vert)container.tg_width.equal(.fill)container.tg_height.equal(.fill)container.backgroundColor = .clearframeContainer.addSubview(container)initFooterContainer()}/// 初始化垂直方向LinearLayout容器,只有顶部不在安全区func initLinearLayoutTopNotSafeArea() {rootContainer = TGRelativeLayout()rootContainer.tg_width.equal(.fill)rootContainer.tg_height.equal(.fill)rootContainer.backgroundColor = .clearself.view.addSubview(rootContainer)container=TGLinearLayout(.vert)container.tg_width.equal(.fill)container.tg_height.equal(.fill)container.backgroundColor = .clearcontainer.tg_bottom.equal(TGLayoutPos.tg_safeAreaMargin)rootContainer.addSubview(container)//headerinitHeaderContainer()}/// 头部容器,安全区外,一般用来设置头部到安全区外背景颜色func initHeaderContainer() {superHeaderContainer = TGLinearLayout(.vert)superHeaderContainer.tg_width.equal(.fill)superHeaderContainer.tg_height.equal(.wrap)superHeaderContainer.backgroundColor = .clear//头部内容容器,安全区内superHeaderContentContainer = TGLinearLayout(.vert)superHeaderContentContainer.tg_height.equal(.wrap)superHeaderContentContainer.tg_leading.equal(TGLayoutPos.tg_safeAreaMargin)superHeaderContentContainer.tg_trailing.equal(TGLayoutPos.tg_safeAreaMargin)superHeaderContentContainer.tg_top.equal(TGLayoutPos.tg_safeAreaMargin)superHeaderContentContainer.backgroundColor = .clearsuperHeaderContainer.addSubview(superHeaderContentContainer)rootContainer.addSubview(superHeaderContainer)}func initFooterContainer() {superFooterContainer = TGLinearLayout(.vert)superFooterContainer.tg_width.equal(.fill)superFooterContainer.tg_height.equal(.wrap)superFooterContainer.backgroundColor = .clear//底部内容容器,安全区内superFooterContentContainer = TGLinearLayout(.vert)superFooterContentContainer.tg_height.equal(.wrap)superFooterContentContainer.tg_leading.equal(TGLayoutPos.tg_safeAreaMargin)superFooterContentContainer.tg_trailing.equal(TGLayoutPos.tg_safeAreaMargin)superFooterContentContainer.tg_bottom.equal(TGLayoutPos.tg_safeAreaMargin)superFooterContentContainer.backgroundColor = .clearsuperFooterContainer.addSubview(superFooterContentContainer)rootContainer.addSubview(superFooterContainer)}}

在这里插入图片描述
这样在controller view中,初始化函数,然后把需要的控件插入即可

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词