table view 的三種 style
就像彼得潘有帥氣,可愛,憂鬱三種 style,table view 也有三種 style,接下來讓讓我們看看這三種 style 的差異吧。
預設的 Plain style
Grouped style
plain & grouped 的表格長得很像,不過在滑動時有個特別的差異。plain 的表格在滑動時,section 的 header & footer 可卡在頂端,方便看出目前 cell 所在的 section。比方以下的通訊錄 App 的 table 為 plain 樣式,滑動時 Header A 將卡在上方,直到我們滑到 Section B 時它才會被 Header B 取代。
Inset Grouped style (iOS 13 以上)
讓 cell 內縮,製作類似卡片的效果。
Style 設為 Inset Grouped。
Background 設為 Default。
Inset grouped style 有很多有趣的變化,讓我們看看更多的例子。
設定 section 區塊的顏色
設定 cell 或 Content View 的 background color。比方我們將愛情片 cell 的 background color 設為黃色,英雄片 cell 的 background color 設為藍色。
透明的 section 區塊
將 cell 的 background color 設為 clear color。
我們也可以移除分隔線,將 table view 的 Separator 設為 none。
只有一個 section,不顯示 section header
一個 section 一個 cell
製造出每個 cell 像是一張卡片的效果。