Xcode 7.1 中使用 XIB 佈局時,UILabel 或 UIScrollView 的垂直滑動條(指示器)不顯示在最右邊,而是靠左或中間,影響 UI 美觀。
contentInset.right 或 scrollIndicatorInsets 導致指示器偏移// 在 viewDidLayoutSubviews 中調用
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
scrollView.scrollIndicatorInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
// 或針對垂直指示器
scrollView.verticalScrollIndicatorInsets = .zero
}
詳細圖文教程可參考:Xcode 7 自動佈局出問題解決匯總
開啟 Debug → View Debugging → Capture View Hierarchy 實時檢查 Frame、Constraints、Safe Area,快速定位佈局偏移源頭。