0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swiftについての覚書7

Last updated at Posted at 2016-12-19

#Toolbarについて
今回はこんな感じのツールバーを作成するサンプルです。

Untitled7.png

##ツールバーのサイズを決める

let myToolbar = UIToolbar(frame: CGRectMake(0, self.view.bounds.size.height - 44, self.view.bounds.size.width, 40.0))

##位置を決める

myToolbar.layer.position = CGPoint(x: self.view.bounds.width/2, y: self.view.bounds.height-20.0)

##色を決める

myToolbar.barStyle = .BlackTranslucent
myToolbar.tintColor = UIColor.whiteColor()
myToolbar.backgroundColor = UIColor.blackColor()

##ボタン1を生成する.
let button1: UIBarButtonItem = UIBarButtonItem(title: "Button1", style:.Plain, target: self, action: #selector(onClickBarButton(_:)))
button1.tag = 1

##ボタン2を生成する.
let button2: UIBarButtonItem = UIBarButtonItem(title: "Button2", style:.Plain, target: self, action: #selector(onClickBarButton(_:)))
button2.tag = 2

##ボタン3を生成する.
let button3: UIBarButtonItem = UIBarButtonItem(title: "Button3", style:.Plain, target: self, action: #selector(onClickBarButton(_:)))
button3.tag = 3

##ボタンの間のスペースを作成
let buttonGap: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)

##ツールバーにボタンとスペースを入れる
myToolbar.items = [button1, buttonGap, button2, buttonGap, button3]

##Viewにツールバーを設定
self.view.addSubview(myToolbar)

完成!!

0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?