swift UITabBar 實現底部tabbar

效果展現swift

問題1 。這圖怎麼這麼奇怪。app

由於圖片是隨便找的圖ide

看網上說合適的圖片設置:ui

1x  :30X30spa

2x  :60X60code

3x  :90X90blog

 

也有講48 x 32 是最合適的。。圖片

沒有ui妹子只能弄個demo圖片。。;了博客

問題2  輪播圖。不錯。。。it

  下片博客貼輪播圖代碼

正式開始

首先建立兩個空的ViewController

HomeViewController

//
//  HomeViewController.swift
//  geekTime
//
//  Created by liuan on 2020/9/14.
//  Copyright © 2020 liuan. All rights reserved.
//

import UIKit
import Kingfisher
class HomeViewController: BaseViewController{


    override func viewDidLoad() {
        super.viewDidLoad()
    

    }
    



}

MineViewController

//
//  MainViewController.swift
//  geekTime
//
//  Created by liuan on 2020/9/14.
//  Copyright © 2020 liuan. All rights reserved.
//

import UIKit

class MineViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

而後修改 ViewController 代碼

//
//  ViewController.swift
//  geekTime
//
//  Created by liuan on 2020/9/14.
//  Copyright © 2020 liuan. All rights reserved.
//

import UIKit

class ViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
         
        let homeVC = HomeViewController()
        homeVC.tabBarItem.image = UIImage(named: "home")
        homeVC.tabBarItem.selectedImage =  UIImage(named: "home_select")?.withRenderingMode(.alwaysOriginal)
        homeVC.tabBarItem.title = "首頁"
         homeVC.tabBarItem.setTitleTextAttributes([.foregroundColor:UIColor.hexColor(0x333333)], for: .selected)
        let navigationHomeVC = UINavigationController(rootViewController: homeVC)
        self.addChild(navigationHomeVC)
        
        let mineVC = MineViewController()
        mineVC.tabBarItem.image =  UIImage(named: "My")
        mineVC.tabBarItem.selectedImage =  UIImage(named: "My_select")?.withRenderingMode(.alwaysOriginal)
        mineVC.tabBarItem.title = "個人"
        mineVC.tabBarItem.setTitleTextAttributes([.foregroundColor:UIColor.hexColor(0x333333)], for: .selected)
        let navigationMineVC = UINavigationController(rootViewController: mineVC)
        self.addChild(navigationMineVC)
        
 
    }


}

把  ViewController 設置爲入口

 

相關文章
相關標籤/搜索