下拉菜单标题与栏按钮重叠 - Swift
Drop Down Menu Title Overlapping with Bar Buttons - Swift
我 long data modules title that overlap with the button on the right. This is a short data module title 标题不重叠。
对于长数据模块,我想创建一个换行符以转到下一行并将其显示在那里,这样它就不会重叠
在我的代码中,我已经将 MaskIntoConstrains 设置为 false,还需要做什么才能使此功能起作用?
代码:
func createDropDownMenu() {
// create the drop down menu
let title = prepareNavigationBarMenuTitleView()
prepareNavigationBarMenu(title)
updateMenuContentOffsets()
}
func prepareNavigationBarMenuTitleView() -> String {
// Both title label and image view are fixed horizontally inside title
// view, UIKit is responsible to center title view in the navigation bar.
// We want to ensure the space between title and image remains constant,
// even when title view is moved to remain centered (but never resized).
titleView = DropDownTitleView(frame: CGRect(x: 0, y: 0, width: 150, height: 40))
titleView.addTarget(self,
action: #selector(DocumentViewController.willToggleNavigationBarMenu(_:)),
for: .touchUpInside)
titleView.addTarget(self,
action: #selector(DocumentViewController.didToggleNavigationBarMenu(_:)),
for: .valueChanged)
titleView.titleLabel.textAlignment = .left
titleView.titleLabel.textColor = UIColor.black
titleView.titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleView.title = currentNode.title
navigationItem.titleView = titleView
return titleView.title!
}
您没有设置 Titlelabel
的框架,设置它的框架并设置 numberofLines = 0
将解决您的问题。
这是代码:
titleView.titleLabel.frame = CGRect(x: 0, y: 0, width: 600, height: 80)
titleView.numberOfLines = 0
//Important one
titleView.titleLabel.text = currentNode.title
这将解决您的问题。享受编码。
我 long data modules title that overlap with the button on the right. This is a short data module title 标题不重叠。
对于长数据模块,我想创建一个换行符以转到下一行并将其显示在那里,这样它就不会重叠
在我的代码中,我已经将 MaskIntoConstrains 设置为 false,还需要做什么才能使此功能起作用?
代码:
func createDropDownMenu() {
// create the drop down menu
let title = prepareNavigationBarMenuTitleView()
prepareNavigationBarMenu(title)
updateMenuContentOffsets()
}
func prepareNavigationBarMenuTitleView() -> String {
// Both title label and image view are fixed horizontally inside title
// view, UIKit is responsible to center title view in the navigation bar.
// We want to ensure the space between title and image remains constant,
// even when title view is moved to remain centered (but never resized).
titleView = DropDownTitleView(frame: CGRect(x: 0, y: 0, width: 150, height: 40))
titleView.addTarget(self,
action: #selector(DocumentViewController.willToggleNavigationBarMenu(_:)),
for: .touchUpInside)
titleView.addTarget(self,
action: #selector(DocumentViewController.didToggleNavigationBarMenu(_:)),
for: .valueChanged)
titleView.titleLabel.textAlignment = .left
titleView.titleLabel.textColor = UIColor.black
titleView.titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleView.title = currentNode.title
navigationItem.titleView = titleView
return titleView.title!
}
您没有设置 Titlelabel
的框架,设置它的框架并设置 numberofLines = 0
将解决您的问题。
这是代码:
titleView.titleLabel.frame = CGRect(x: 0, y: 0, width: 600, height: 80)
titleView.numberOfLines = 0
//Important one
titleView.titleLabel.text = currentNode.title
这将解决您的问题。享受编码。