封装常用控制器

封装常用控制器

复制代码
//
//  BaseLogicController.swift
//  项目中通用的逻辑控制器

import UIKit
import TangramKit

class BaseLogicController: BaseCommonController {
    /// 根容器
    var rootContainer:TGBaseLayout!
    
    /// 头部容器
    var superHeaderContainer:TGBaseLayout!
    var superHeaderContentContainer:TGBaseLayout!
    
    /// 底部容器
    var superFooterContainer:TGBaseLayout!
    var superFooterContentContainer:TGBaseLayout!
    
    /// 容器
    var container:TGBaseLayout!
    
    /// 初始化RelativeLayout容器,四边都在安全区内
    func initRelativeLayoutSafeArea() {
        initLinearLayout()
        
        //header
        initHeaderContainer()
        
        container = TGRelativeLayout()
        container.tg_width.equal(.fill)
        container.tg_height.equal(.fill)
        container.backgroundColor = .clear
        rootContainer.addSubview(container)
        
        initFooterContainer()
    }
    
    /// 初始化垂直方向LinearLayout容器,四边都在安全区内
    func initLinearLayoutSafeArea() {
        initLinearLayout()
        
        //header
        initHeaderContainer()
        
        //frame
        frameContainer=TGRelativeLayout();
        frameContainer.tg_width.equal(.fill)
        frameContainer.tg_height.equal(.fill)
        frameContainer.backgroundColor = .clear
        rootContainer.addSubview(frameContainer)
        
        container = TGLinearLayout(.vert)
        container.tg_width.equal(.fill)
        container.tg_height.equal(.fill)
        container.backgroundColor = .clear
        frameContainer.addSubview(container)
        
        initFooterContainer()
    }
    

    
    
    /// 初始化垂直方向LinearLayout容器,只有顶部不在安全区
    func initLinearLayoutTopNotSafeArea() {
        rootContainer = TGRelativeLayout()
        rootContainer.tg_width.equal(.fill)
        rootContainer.tg_height.equal(.fill)
        rootContainer.backgroundColor = .clear
        self.view.addSubview(rootContainer)
        
        container=TGLinearLayout(.vert)
        container.tg_width.equal(.fill)
        container.tg_height.equal(.fill)
        container.backgroundColor = .clear
        container.tg_bottom.equal(TGLayoutPos.tg_safeAreaMargin)
        rootContainer.addSubview(container)
        
        //header
        initHeaderContainer()
    }

    
    /// 头部容器,安全区外,一般用来设置头部到安全区外背景颜色
    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 = .clear
        
        superHeaderContainer.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 = .clear
        
        superFooterContainer.addSubview(superFooterContentContainer)
        rootContainer.addSubview(superFooterContainer)
    }
    
}

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

相关推荐
卷心菜加农炮2 小时前
基于Python的FastAPI后端开发框架如何使用PyInstaller 进行打包与部署
ios
北极象12 小时前
千问大模型接入示例
ios·iphone·qwen
ipad协议开发14 小时前
企业微信 iPad 协议应用机器人开发
ios·企业微信·ipad
kkoral15 小时前
基于MS-Swift 为 Qwen3-0.6B-Base 模型搭建可直接调用的 API 服务
python·conda·fastapi·swift
QuantumLeap丶1 天前
《Flutter全栈开发实战指南:从零到高级》- 26 -持续集成与部署
android·flutter·ios
2501_915918411 天前
TCP 抓包分析在复杂网络问题中的作用,从连接和数据流层面理解系统异常行为
网络·网络协议·tcp/ip·ios·小程序·uni-app·iphone
二流小码农1 天前
鸿蒙开发:个人开发者如何使用华为账号登录
android·ios·harmonyos
Yorelee.1 天前
ms-swift在训练时遇到的部分问题及解决方案
开发语言·nlp·transformer·swift
wvy2 天前
Xcode 26还没有适配SceneDelegate的app建议尽早适配
ios
游戏开发爱好者82 天前
苹果 App 上架流程,结合 Xcode、CI 等常见工具
macos·ios·ci/cd·小程序·uni-app·iphone·xcode