对齐下拉菜单标题以防止其他按钮重叠

时间:2017-05-29 12:15:43

标签: swift user-interface drop-down-menu menu title

我有下面的图像,其中下拉菜单标题的标题与其他按钮重叠。 如何解决此问题?

enter image description here

代码:

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.lineBreakMode = NSLineBreakMode.byClipping
    titleView.titleLabel.numberOfLines = 2
    titleView.titleLabel.textColor = UIColor.black
    titleView.title = currentNode.title
    navigationItem.titleView = titleView
    return titleView.title!
}

1 个答案:

答案 0 :(得分:0)

我必须设置TitleLable的框架并设置numberOfLines = 0来解决我的问题。

代码:

titleView.titleLabel.frame = CGRect(x: 0, y: 0, width: 600, height: 80)
titleView.numberOfLines = 0

titleView.titleLabel.text = currentNode.title