は、私が試したコードです。
import UIKit
class ViewController2 : UIViewController {
@IBOutlet weak var mytoolbar: UIToolbar!
override func viewDidLoad() {
super.viewDidLoad();
let sendButton = UIBarButtonItem(title: "test", style: .Plain, target: self, action: nil)
let toolBarItems = [UIBarButtonItem(barButtonSystemItem: .Camera, target: self, action: nil),
UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: self, action: nil),
sendButton]
mytoolbar.items = toolBarItems
}
}
編集:私はプログラムでuitoolbarを作成するために、以下のコードを使用してい。
それが中央に配置され、私は推測する:
let mytoolbar = UIToolbar.init(frame: CGRect(x: 0 , y: 0, width:self.view.frame.size.width, height: 44))
mytoolbar.backgroundColor = UIColor.blueColor()
let sendButton = UIBarButtonItem(title: "test", style: .Plain, target: self, action: nil)
let toolBarItems = [UIBarButtonItem(barButtonSystemItem: .Camera, target: self, action: nil),
UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: self, action: nil),
sendButton]
mytoolbar.items = toolBarItems
self.view.addSubview(mytoolbar)
希望はこれが今 はここでの結果であるのに役立ちます。 UIToolbarを追加するコードを教えてください。
これは何か他のものが中断している可能性があります。このコードは、ビューコントローラの下のツールバーの中央にテストボタンを表示します。 –
あなたは何を言っているのか分かりません。これは簡単なUIツールバーです。 – Rafthecalf
私が言っていることは、sendButtonのアクションを除いてあなたのコードを試したことです。私は通常のビューコントローラを取って、意図した通りに動作するコンセントを追加し、途中でテストを表示します。あなたの制約には間違いはありませんか?それは影響を与えるべきではありませんが、それを確認してください。 –