UIToolbar标题重叠完成按钮

时间:2015-10-03 12:12:29

标签: ios swift autolayout uitoolbar

我想创建一个带有右对齐完成按钮和左对齐标题/标签的UIToolbar。

我目前的解决方案适用于短标签,但与长标签重叠

使用autolayout我将水平间距设置为0,并确保我的done文本的压缩阻力高于标题文本。但是使用UIToolbar api我不确定如何实现这一点。

Overlap Issue

以下是生成此代码的代码:

lazy var pickerToolbar: UIToolbar = {
  let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 0, height: 33))
  let leftTitle = UIBarButtonItem(title: "One and only one with lots of choices", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
  leftTitle.tintColor = UIColor.blackColor()
  let space     = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
  let closeBtn  = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "onTapClose")
  toolbar.setItems([
    leftTitle,
    space,
    closeBtn
  ], animated: false)
  return toolbar
}()

// ...later
textField.inputAccessoryView = pickerToolbar

0 个答案:

没有答案