iOS 導航欄可設定左右按鈕與標題。若需要圖文並用的標題,可自訂 titleView。
透過 navigationItem 的 leftBarButtonItem、rightBarButtonItem 可加入導航按鈕;titleView 可放入自訂 UIButton,顯示文字與下拉箭頭。
若要讓圖片在右、文字在左,可建立 UIButton 子類,重寫 imageRectForContentRect: 與 titleRectForContentRect:,調整內部圖片與文字的位置。
點擊標題按鈕時,可根據目前狀態切換上箭頭或下箭頭。實作時可用 currentImage 判斷,避免額外狀態變數或魔法數字。