封装常用控制器

封装常用控制器

//
//  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中,初始化函数,然后把需要的控件插入即可

相关推荐
Mr.NickJJ4 小时前
Swift系列02-Swift 数据类型系统与内存模型
开发语言·ios·swift
二流小码农4 小时前
鸿蒙开发:wrapBuilder传递参数
android·ios·harmonyos
火柴就是我6 小时前
flutter rust bridge 编译成so 文件 或者 .a文件 依赖到主项目
flutter·ios·rust
YungFan7 小时前
iOS开发之网络代码进化史
ios·swift
SunshineBrother13 小时前
shell脚本,怎么查找项目中的重复图片
ios
月未央13 小时前
HarmonyOS Next 开发系列:Provider和Consumer状态修饰器实践
ios·harmonyos
北京自在科技1 天前
【Find My功能科普】防盗黑科技如何改变生活?
科技·ios·生活·findmy
水木姚姚2 天前
图形界面控件编程(iOS)
人工智能·python·macos·ios·xcode
书弋江山2 天前
Flutter 调用原生IOS接口
flutter·ios·cocoa
q567315233 天前
使用ASIWebPageRequest库编写Objective-C下载器程序
android·开发语言·macos·ios·objective-c·iphone