facebook twitter hatena line email

Ios/swift/UIToolbar

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

UIToolbarとは

フッターのボタン一覧を追加できるUI

サンプル

var footerToolbar: UIToolbar!
footerToolbar = UIToolbar(frame: CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40.0))
footerToolbar.layer.position = CGPoint(x: self.view.bounds.width/2, y: self.view.bounds.height-20.0)
footerToolbar.barStyle = .BlackTranslucent
footerToolbar.tintColor = UIColor.whiteColor()
footerToolbar.backgroundColor = UIColor.blackColor()
let myUIBarButtonGreen: UIBarButtonItem = UIBarButtonItem(title: "Green", style:.Plain, target: self, action: Selector("onClickBarButton:"))
myUIBarButtonGreen.tag = 1
let myUIBarButtonBlue: UIBarButtonItem = UIBarButtonItem(title: "Blue", style:.Plain, target: self, action: Selector("onClickBarButton:"))
myUIBarButtonBlue.tag = 2
footerToolbar.items = [myUIBarButtonGreen, myUIBarButtonBlue]
self.view.addSubview(footerToolbar)

参考:https://sites.google.com/a/gclue.jp/swift-docs/ni-yinki100-ios/uikit/027-uitoolbarno-biao-shi

toolbarを削除する場合

footerToolbar.removeFromSuperview()

参考:http://qiita.com/h_nagami/items/7485cee8b73849f0c847