簡體   English   中英

如何在選擇器視圖(swift4)上將工具欄按鈕居中

[英]how to center tool bar button on picker view (swift4)

我想在工具欄上將按鈕居中。 當前,按鈕自動轉到右側。

let toolbar = UIToolbar()
toolbar.sizeToFit()

您只需在按鈕之間添加2個flexibleSpace。

例如:

let toolbar = UIToolbar(frame: CGRect(x: 0, y: UIApplication.shared.statusBarFrame.height, width: view.bounds.width, height: 44))

var items = [UIBarButtonItem]()

items.append( UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil) )
items.append( UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(test)) )
items.append( UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil) )

toolbar.items = items
self.view.addSubview(toolbar)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM