iT邦幫忙

2023 iThome 鐵人賽

DAY 24
0
Mobile Development

App從開發到上架系列 第 24

Day26: iOS 開發:優化一些畫面以及功能吧!

  • 分享至 

  • xImage
  •  
enum BottomItems: Int, CaseIterable {
    case HomeViewController = 0, FindingViewController, WalletViewController, NewsViewController, MemberShipViewController

    var title: String {
        switch self {
        case .HomeViewController:
            return "首頁"
        case .FindingViewController:
            return "尋找餐廳"
        case .WalletViewController:
            return "錢包"
        case .NewsViewController:
            return "最新消息"
        case .MemberShipViewController:
            return "會員中心"
        }
    }

    var imageName: String {
        switch self {
        case .HomeViewController:
            return "home"
        case .FindingViewController:
            return "search"
        case .WalletViewController:
            return "wallet-filled-money-tool"
        case .NewsViewController:
            return "megaphone"
        case .MemberShipViewController:
            return "user"
        }
    }
}

//
//  ViewController.swift
//  FoodDemo
//
//  Created by Wang Allen on 2023/9/19.
//

import UIKit

enum BottomItems: Int, CaseIterable {
    case HomeViewController = 0, FindingViewController, WalletViewController, NewsViewController, MemberShipViewController

    var title: String{
        switch self {
        case .HomeViewController:
            return "首頁"
        case .FindingViewController:
            return "尋找餐廳"
        case .WalletViewController:
            return "錢包"
        case .NewsViewController:
            return "最新消息"
        case .MemberShipViewController:
            return "會員中心"
        }
    }
    
}

class CustomTabBar: UIView {

    @IBOutlet weak var homeView: CustomTabBarView!
    @IBOutlet weak var findingView: CustomTabBarView!
    @IBOutlet weak var walletView: CustomTabBarView!
    @IBOutlet weak var newsView: CustomTabBarView!
    @IBOutlet weak var membershipView: CustomTabBarView!
    
    var buttonTapped: ((Int) -> ())? = nil
    var items = BottomItems.allCases
    var orangeColor = UIColor(red: 255/255, green: 137/255, blue: 56/255, alpha: 1)
    var cell: [UIImageView] = []
    
    override func awakeFromNib() {
        super.awakeFromNib()
        addXibView()
        self.homeView.viewControllerImg.tintColor = .orange
        cell.append(homeView.viewControllerImg)
        cell.append(findingView.viewControllerImg)
        cell.append(walletView.viewControllerImg)
        cell.append(newsView.viewControllerImg)
        cell.append(membershipView.viewControllerImg)
        

    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              func changeColor(tag: Int) {
        for i in 0 ..< cell.count {
            cell[i].tintColor = (i == tag) ? .systemOrange : .lightGray
        }
    }
}

extension CustomTabBar: CustomViewListener {
    func target(stringTag: Int) {
        buttonTapped?(items[stringTag].rawValue)
        changeColor(tag: stringTag)
    }
}

fileprivate extension CustomTabBar {
    //加入畫面
    func addXibView() {
        if let loadView = Bundle(for: CustomTabBar.self).loadNibNamed("CustomTabBar", owner: self, options: nil)?.first as? UIView{
            addSubview(loadView)
            loadView.frame = bounds
        }
        homeView.delegate = self
        findingView.delegate = self
        walletView.delegate = self
        newsView.delegate = self
        membershipView.delegate = self
        
        homeView.setInit(tag: 0, text: "首頁", image: UIImageView.init(image: UIImage(named: "home")), tinColor: .lightGray)
        findingView.setInit(tag: 1, text: "尋找餐廳", image: UIImageView.init(image: UIImage(named: "search")), tinColor: .lightGray)
        walletView.setInit(tag: 2, text: "錢包", image: UIImageView.init(image: UIImage(named: "wallet-filled-money-tool")), tinColor: .lightGray)
        newsView.setInit(tag: 3, text: "最新消息", image: UIImageView.init(image: UIImage(named: "megaphone")), tinColor: .lightGray)
        membershipView.setInit(tag: 4, text: "會員中心", image: UIImageView.init(image: UIImage(named: "user")), tinColor: .lightGray)
          
    }
}


上一篇
Day25: iOS 開發:簡單的餐廳訂位功能 - 試著把前後端給串接起來!
下一篇
Day27: iOS 上架:發布TestFlight
系列文
App從開發到上架30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言