最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[未解决]swift实现在特定一块矩形区域内添加tab按钮页面

Swift crifan 2614浏览 0评论
[背景]
需要在一个页面中,在已经加入了一些显示元素后。
下部分,加入具有3个tab按钮的显示页面或区域。
[折腾过程]
1.搜:
swift tab view
参考:
Swift Swift: Using Tab Bar Controllers in Swift | Making App Pie
Tab bar for Xcode Swift for iOS – YouTube
Tab Bar Controller Tutorial in iOS8 with Swift – iOScreator
Starting an iOS Tab Bar App with UITabBarViewController
UITabBarController Class Reference
先看看官网的解释。
tab的话,每个tab页面,点击后,页面内容都是重新刷,重新画的。
2.
3.但是又遇到:
4.最后用代码:
let tabSubView = UIView(frame: CGRectMake(
0,
//statusView.frame.height + ownedSchoolCoinBgView.frame.height + tabbgView.frame.height,
0,
self.view.frame.width,
self.view.bounds.size.height – ownedSchoolCoinBgView.frame.origin.y
))

print(“tabSubView.frame=\(tabSubView.frame)”)

let recordTabBarView = UITabBarController()
//let allRecordTab = AllRecordTabViewController(nibName: “全部记录”, bundle: nil)
let allRecordTab = AllRecordTabViewController()
//let incomeRecordTab = IncomeRecordTabViewController(nibName: “收入记录”, bundle: nil)
let incomeRecordTab = IncomeRecordTabViewController()
//let expenseRecordTab = ExpenseRecordTabViewController(nibName: “支出记录”, bundle: nil)
let expenseRecordTab = ExpenseRecordTabViewController()
let tabControllers = [allRecordTab, incomeRecordTab, expenseRecordTab]

recordTabBarView.viewControllers = tabControllers
recordTabBarView.selectedIndex = 2

//self.addChildViewController(recordTabBarView)
tabSubView.addSubview(recordTabBarView.view)

        self.view.addSubview(tabSubView)
AllRecordTabViewController.swift
import UIKit

class AllRecordTabViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = UIColor.greenColor()
self.title = “全部记录”
}

}
IncomeRecordTabViewController.swift
import UIKit

class IncomeRecordTabViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = UIColor.yellowColor()
self.title = “收入记录”

}

}
ExpenseRecordTabViewController.swift
import UIKit

class ExpenseRecordTabViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = UIColor.cyanColor()
self.title = “支出记录”

    }
}
实现了可以添加tab了:
show basic tab bar
不过很明显,还是没有完全满足要求:
此处,只能全屏幕的去显示tab,而不能在当前页面的下半部的去显示tab。
5.所以还要解决:
还是没解决。
6.继续自己折腾。
打算,先从最基本多tab的写法去入手。
等熟悉了之后,再去想办法定制高度。

转载请注明:在路上 » [未解决]swift实现在特定一块矩形区域内添加tab按钮页面

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
85 queries in 0.163 seconds, using 22.15MB memory