Display a CustomView for the empty state
masterYou can display a completely custom view instead of the default title/image/button layout.
Important Rules:
- Conflict Resolution: If you set
customViewviaEmptyDataSetSource, other settings (like title/image) will be ignored. If you set it via theemptyDataSetViewextension, AutoLayout for other elements will be invalid. - Positioning: The
customViewis centered in thetableView. - Alignment: You can adjust the vertical position using
verticalOffset(forEmptyDataSet:)in the source or.verticalOffset()in the extension. - Sizing: The view's size is determined by its frame. However, if the view is a
UILabelwith aCGRect.zeroframe, its width and height will be determined by its content via AutoLayout.
Example (Source Protocol):
func customView(forEmptyDataSet scrollView: UIScrollView) -> UIView? {
let view = CustomView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
return view
}
func verticalOffset(forEmptyDataSet scrollView: UIScrollView) -> CGFloat {
return 200
}func customView(forEmptyDataSet scrollView: UIScrollView) -> UIView? {
let view = CustomView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
return view
}