0
在我的UIView子類中,我添加了下面的init方法,然後將該視圖作爲navigationItem的titleView分配。我看到一個紅色的矩形,意思是這個視圖在那裏,但我沒有看到黃色的滾動視圖。我在這裏做錯了什麼?UIScrollView在UINavigationItem中不顯示
open class ChatNavBarImagesView : UIView {
private let scrollView = UIScrollView()
public init(navigationController: UINavigationController) {
let height = navigationController.navigationBar.frame.height
super.init(frame: CGRect(x: 0, y: 0, width: 200, height: height))
backgroundColor = UIColor.red
addSubview(scrollView)
scrollView.leadingAnchor.constraint(equalTo: leadingAnchor)
scrollView.trailingAnchor.constraint(equalTo: trailingAnchor)
scrollView.topAnchor.constraint(equalTo: topAnchor)
scrollView.bottomAnchor.constraint(equalTo: bottomAnchor)
scrollView.backgroundColor = UIColor.yellow
scrollView.contentSize = CGSize(width: 200, height: height)
}
的邊界所需的視圖的任何圖像/截圖和實際的視圖可能有幫助。 – Adeel