swift 适用于iOS的标题TabBar
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift 适用于iOS的标题TabBar相关的知识,希望对你有一定的参考价值。
//
// InvestmentFundesViewController.swift
// Intermedium
//
// Created by Marwen Jamel on 20/09/18.
// Copyright © 2018 iOasys. All rights reserved.
//
import UIKit
import Intercom
protocol InvestmentFundesViewControllerDelegate: class {
func didSelect(menuOption: InvestmentHomeItem, on viewController: InvestmentFundesViewController)
}
class InvestmentFundesViewController: MenuChildViewController {
// MARK: - IBOutlets
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var minhaCarteiraLabel: UILabel!
@IBOutlet weak var queroInvestirLabel: UILabel!
@IBOutlet weak var minhaCarteiraContainer: UIView!
@IBOutlet weak var queroInvestirContainer: UIView!
@IBOutlet weak var scrollIndicatorLeftConstraint: NSLayoutConstraint!
// MARK: - Variables
var accountInfo: AccountInfo!
var isIwantToInvestSelected: Bool?
weak var delegate: InvestmentFundesViewControllerDelegate?
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
if isIwantToInvestSelected == false {
DispatchQueue.main.async {
self.scrollView.setContentOffset(CGPoint(x: self.view.frame.size.width * CGFloat(0), y: 0), animated: true)
self.activeLabel(label: self.minhaCarteiraLabel)
self.deactivatesLabel(label: self.queroInvestirLabel)
}
}else {
DispatchQueue.main.async {
self.scrollView.setContentOffset(CGPoint(x: self.view.frame.size.width * CGFloat(1), y: 0), animated: true)
self.activeLabel(label: self.queroInvestirLabel)
self.deactivatesLabel(label: self.minhaCarteiraLabel)
}
}
}
@IBAction func didTapMinhaCarteira(_ sender: Any) {
self.scrollView.setContentOffset(CGPoint(x: self.view.frame.size.width * CGFloat(0), y: 0), animated: true)
activeLabel(label: minhaCarteiraLabel)
deactivatesLabel(label: queroInvestirLabel)
self.updateIntercomVisibility(visible: false)
}
@IBAction func didTapQueroInvestir(_ sender: Any) {
self.scrollView.setContentOffset(CGPoint(x: self.view.frame.size.width * CGFloat(1), y: 0), animated: true)
activeLabel(label: queroInvestirLabel)
deactivatesLabel(label: minhaCarteiraLabel)
self.updateIntercomVisibility(visible: true)
}
// MARK: - Navigation
override func goBack() {
self.updateIntercomVisibility(visible: false)
_ = self.navigationController?.popViewController(animated: true)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "investmentStatment" {
let controller = segue.destination as! InvestmentStatementViewController
controller.delegate = (self as InvestmentStatementViewControllerDelegate)
controller.accountInfo = self.accountInfo
self.delegate?.setHomeViewController(viewController: controller)
}else{
let controller = segue.destination as! IwantToInvestViewController
controller.accountInfo = self.accountInfo
controller.delegate = self
}
}
func activeLabel(label:UILabel){
label.textColor = Colors.orange
}
func deactivatesLabel(label:UILabel){
label.textColor = #colorLiteral(red: 0.5490196078, green: 0.568627451, blue: 0.662745098, alpha: 1)
}
}
// MARK: - UIScrollViewDelegate
extension InvestmentFundesViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
self.scrollIndicatorLeftConstraint.constant = scrollView.contentOffset.x / 2
print("valor quando entrou: " + String(describing: scrollView.contentOffset.x / self.view.frame.size.width))
if scrollView.contentOffset.x / self.view.frame.size.width < 1.0 {
print("First View")
activeLabel(label: minhaCarteiraLabel)
deactivatesLabel(label: queroInvestirLabel)
}else if scrollView.contentOffset.x / self.view.frame.size.width < 2.0 {
print("Second View")
activeLabel(label: queroInvestirLabel)
deactivatesLabel(label: minhaCarteiraLabel)
}
self.view.layoutIfNeeded()
}
}
以上是关于swift 适用于iOS的标题TabBar的主要内容,如果未能解决你的问题,请参考以下文章
适用于 iOS 的 Swift NativeModule 始终为空
尝试访问 TabBar 时 IOS swift 致命错误 nil 异常
适用于 iOS 7.1 的带有 swift 的 SKShapeNode