3
5

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 3 years have passed since last update.

Swift5 スクロールビューをコードで実装してみた

Last updated at Posted at 2019-12-25

始めに

今回はスクロールビューをコードで実装したいと思います。
ストリートボードで作成するやり方もありますが、色々手間が多いのでやりたくない方は必見です。
※自分用メモです。

実装

Test.swift
//スクリーンの幅
let screenWidth = Int( UIScreen.main.bounds.size.width)
//スクリーンの高さ
let screenHeight = Int(UIScreen.main.bounds.size.height)
//UIScrollViewのインスタンス作成
let scrollView = UIScrollView()
//scrollViewの大きさを設定
scrollView.frame = self.view.frame
//スクロール領域の設定
scrollView.contentSize = CGSize(width:screenWidth, height:screenHeight)
//scrollViewをviewのSubViewとして追加
self.view.addSubview(scrollView)
//表示ラベル
let sideMenuLabel = UILabel(frame: CGRect(x:0, y:0, width:screenWidth, height:320))
//表示可能最大行数を指定
sideMenuLabel.numberOfLines = 0
sideMenuLabel.font = sideMenuLabel.font.withSize(9)
sideMenuLabel.text = "テストで表示"
scrollView.addSubview(sideMenuLabel)
3
5
0

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
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?