[英]How to move prompt position below title OR move back button position
我想在它下面放一個帶有小文字的大標題而不用后退按鈕向下移動。
我將時間設置為標題,這與我想要的相反,以便將名稱放在頂部
navigationItem.titleView
: 在第二張照片中,我正在向navigationBar
添加高度。 這非常接近我想要的,但我希望后退按鈕保持在頂部。 如果我可以移動后退按鈕,我可以更改自定義titleView的約束。
當前代碼:
func createTitleView() {
let titleView = UIView()
let titleLabel = UILabel()
titleLabel.text = "Pete's Diner"
titleLabel.textColor = UIColor.whiteColor()
titleLabel.font = UIFont.boldSystemFontOfSize(16.0)
titleLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
let descLabel = UILabel()
descLabel.text = "Open 9AM - 9PM"
descLabel.textColor = UIColor.whiteColor()
descLabel.font = UIFont.systemFontOfSize(14.0)
descLabel.setTranslatesAutoresizingMaskIntoConstraints(false)
titleView.addSubview(titleLabel)
titleView.addSubview(descLabel)
titleView.addConstraint(NSLayoutConstraint(
item: titleView, attribute: .CenterX, relatedBy: .Equal,
toItem: titleLabel, attribute: .CenterX, multiplier: 1.0, constant: 0))
titleView.addConstraint(NSLayoutConstraint(
item: titleView, attribute: .CenterX, relatedBy: .Equal,
toItem: descLabel, attribute: .CenterX, multiplier: 1.0, constant: 0))
titleView.addConstraint(NSLayoutConstraint(
item: titleView, attribute: NSLayoutAttribute.CenterYWithinMargins, relatedBy: NSLayoutRelation.Equal,
toItem: titleLabel, attribute: NSLayoutAttribute.CenterYWithinMargins, multiplier: 1.0, constant: 12))
titleView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
"V:[titleLabel]-2-[descLabel]", options: nil, metrics: nil, views: ["titleLabel": titleLabel, "descLabel": descLabel]))
navigationItem.titleView = titleView
let nav = navigationController?.navigationBar
nav!.barTintColor = UIColor.customGreenColor()
nav!.tintColor = UIColor.whiteColor()
nav!.translucent = false
nav!.frame.size.height = 60.0
}
邊欄:
視圖出現后約500ms才會設置約束。 我已經嘗試在viewDidLayoutSubviews
設置titleView
,但沒有幫助。 如果有人能幫助我,我將不勝感激。 我認為這是一個navigationBar /自定義titleView問題。
我通過在視圖中添加最頂層的自定義視圖解決了這個問題,然后添加了一個標簽,它將作為字幕標簽。
通過使此自定義視圖停靠在導航欄的底部,跨越屏幕的整個寬度並使其高度取決於標簽字體大小以及標簽的頂部/底部邊距,視圖將緊密地放置在導航欄。
然后,您應該將導航欄和自定義視圖配置為具有相同的背景顏色,然后刪除導航欄的陰影圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.