下拉菜单标题重叠酒吧按钮 - 斯威夫特

时间:2017-05-24 14:38:52

标签: swift drop-down-menu title uibarbuttonitem line-breaks

我的long data modules title与右侧的按钮重叠。这是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!
}

1 个答案:

答案 0 :(得分:1)

您没有设置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

这将解决您的问题。享受编码。