封装常用控制器

封装常用控制器

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

相关推荐
Swift社区6 小时前
LeetCode - #196 删除重复的电子邮件并保留最小 ID 的唯一电子邮件
vue.js·算法·leetcode·swift
一丝晨光6 小时前
为什么会有函数调用参数带标签的写法?Swift函数调用的参数传递需要加前缀是否是冗余?函数调用?函数参数?
java·开发语言·c++·ios·c#·objective-c·swift
DZh_Ming18 小时前
IOS开发日志-ios新建项目后-将storyboard去掉,版本调整为IOS13以下
macos·ios·cocoa
小鹿撞出了脑震荡20 小时前
Effective Objective-C 2.0 读书笔记—— 接口与API设计
开发语言·ios·objective-c
小鹿撞出了脑震荡20 小时前
Effective Objective-C 2.0 读书笔记——类对象
开发语言·ios·objective-c
Swift社区1 天前
LeetCode - #197 Swift 实现找出温度更高的日期
算法·leetcode·swift
職場上的造物主2 天前
高清种子资源获取指南 | ✈️@seedlinkbot
python·ios·php·音视频·视频编解码·视频
Kevin Coding3 天前
Flutter使用Flavor实现切换环境和多渠道打包
android·flutter·ios
wn5315 天前
【浏览器 - Mac实时调试iOS手机浏览器页面】
前端·macos·ios·智能手机·浏览器