facebook twitter hatena line email

「Ios/swift/UIToolbar」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==UIToolbarとは== フッターのボタン一覧を追加できるUI ==サンプル== var myToolbar: UIToolbar! myToolbar = UIToolbar(frame: CGRectMake...」)
 
 
行3: 行3:
  
 
==サンプル==
 
==サンプル==
        var myToolbar: UIToolbar!
+
var footerToolbar: UIToolbar!
        myToolbar = UIToolbar(frame: CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40.0))
+
footerToolbar = UIToolbar(frame: CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40.0))
        myToolbar.layer.position = CGPoint(x: self.view.bounds.width/2, y: self.view.bounds.height-20.0)
+
footerToolbar.layer.position = CGPoint(x: self.view.bounds.width/2, y: self.view.bounds.height-20.0)
        myToolbar.barStyle = .BlackTranslucent
+
footerToolbar.barStyle = .BlackTranslucent
        myToolbar.tintColor = UIColor.whiteColor()
+
footerToolbar.tintColor = UIColor.whiteColor()
        myToolbar.backgroundColor = UIColor.blackColor()
+
footerToolbar.backgroundColor = UIColor.blackColor()
        let myUIBarButtonGreen: UIBarButtonItem = UIBarButtonItem(title: "Green", style:.Plain, target: self, action: Selector("onClickBarButton:"))
+
let myUIBarButtonGreen: UIBarButtonItem = UIBarButtonItem(title: "Green", style:.Plain, target: self, action: Selector("onClickBarButton:"))
        myUIBarButtonGreen.tag = 1
+
myUIBarButtonGreen.tag = 1
        let myUIBarButtonBlue: UIBarButtonItem = UIBarButtonItem(title: "Blue", style:.Plain, target: self, action: Selector("onClickBarButton:"))
+
let myUIBarButtonBlue: UIBarButtonItem = UIBarButtonItem(title: "Blue", style:.Plain, target: self, action: Selector("onClickBarButton:"))
        myUIBarButtonBlue.tag = 2
+
myUIBarButtonBlue.tag = 2
        myToolbar.items = [myUIBarButtonGreen, myUIBarButtonBlue]
+
footerToolbar.items = [myUIBarButtonGreen, myUIBarButtonBlue]
        self.view.addSubview(myToolbar)
+
self.view.addSubview(footerToolbar)
  
 
参考:https://sites.google.com/a/gclue.jp/swift-docs/ni-yinki100-ios/uikit/027-uitoolbarno-biao-shi
 
参考:https://sites.google.com/a/gclue.jp/swift-docs/ni-yinki100-ios/uikit/027-uitoolbarno-biao-shi
  
 
==toolbarを削除する場合==
 
==toolbarを削除する場合==
        myToolbar.removeFromSuperview()
+
footerToolbar.removeFromSuperview()
 
参考:http://qiita.com/h_nagami/items/7485cee8b73849f0c847
 
参考:http://qiita.com/h_nagami/items/7485cee8b73849f0c847

2016年7月30日 (土) 17:32時点における最新版

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