iT邦幫忙

2025 iThome 鐵人賽

DAY 6
0
Mobile Development

Xcode x Swift Vibe coding進階開發之旅系列 第 6

Development Xcode x Swift Vibe coding進階開發之旅 第6天 點名系統(2) 使用指令設定navbar

  • 分享至 

  • xImage
  •  

指令及回答

指令:/images/emoticon/emoticon08.gif
https://ithelp.ithome.com.tw/upload/images/20250919/2016818729sSDhLDlA.png
回答:/images/emoticon/emoticon10.gif
https://ithelp.ithome.com.tw/upload/images/20250919/20168187GEwFlMoFRm.png

實際內容

override func viewDidLoad() {
        super.viewDidLoad()
        
        // 設置導航欄標題
        title = "簽到系統"
        
        // 設置淡藍色導航欄
        setupNavigationBar()
        
        // 設置"記錄"按鈕
        setupRecordButton()
    }
    
    // 設置淡藍色導航欄
    private func setupNavigationBar() {
        let appearance = UINavigationBarAppearance()
        appearance.configureWithOpaqueBackground()
        appearance.backgroundColor = UIColor(red: 173/255, green: 216/255, blue: 230/255, alpha: 1.0) // 淡藍色
        appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
        
        navigationController?.navigationBar.standardAppearance = appearance
        navigationController?.navigationBar.scrollEdgeAppearance = appearance
        navigationController?.navigationBar.compactAppearance = appearance
        
        // 確保導航欄不透明
        navigationController?.navigationBar.isTranslucent = false
    }
    
    // 設置"記錄"按鈕
    private func setupRecordButton() {
        let recordButton = UIBarButtonItem(title: "記錄", style: .plain, target: self, action: #selector(recordButtonTapped))
        navigationItem.rightBarButtonItem = recordButton
    }
    
    // 記錄按鈕點擊事件
    @objc private func recordButtonTapped() {
        // 未來這裡會導航到記錄頁面
        print("記錄按鈕被點擊")
        
        // 這裡可以添加跳轉到記錄頁面的代碼
        // let recordVC = RecordViewController()
        // navigationController?.pushViewController(recordVC, animated: true)
    }

上一篇
Development Xcode x Swift Vibe coding進階開發之旅 第五天 點名系統(1) 下指令建立realm資料架構
下一篇
Development Xcode x Swift Vibe coding進階開發之旅 第7天 點名系統(3) 建立主畫面及紀錄畫面
系列文
Xcode x Swift Vibe coding進階開發之旅9
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言