1
2

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.

Swift - viewの影

Posted at

swiftでviewに影をつける基本の四つのプロパティ

simple.swift
testView.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
testView.layer.shadowColor = UIColor.black.cgColor
testView.layer.shadowOpacity = 0.6
testView.layer.shadowRadius = 4

#影の方向 shadowOffset
heightは縦方向です、正数は下、負数は上です。
截圖 2021-09-06 21.46.54.png
截圖 2021-09-06 21.50.23.png

simple.swift
//影は下にある
testView.layer.shadowOffset = CGSize(width: 0.0, height: 30.0)
//影は上にある
testView.layer.shadowOffset = CGSize(width: 0.0, height: -30.0)

widthは横方向です、正数は右、負数は左です。
截圖 2021-09-06 21.54.46.png
截圖 2021-09-06 21.55.27.png

simple.swift
//影は右にある
testView.layer.shadowOffset = CGSize(width: 30.0, height: 0.0)
//影は左にある
testView.layer.shadowOffset = CGSize(width: -30.0, height: 0.0)

#影の色 shadowColor
截圖 2021-09-06 21.57.32.png

simple.swift
testView.layer.shadowColor = UIColor.blue.cgColor

#影の透明度 shadowOpacity
範囲は0〜1です。0が透明、1が不透明です。
截圖 2021-09-06 22.00.10.png

simple.swift
testView.layer.shadowOpacity = 0.2

#影の幅 shadowRadius
截圖 2021-09-06 22.03.49.png

simple.swift
testView.layer.shadowRadius = 30.0

#終わりに
わかりやすいようにちょっと大げさな数値を入れましたので、自分のニーズで調整してください。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?