[UIKit][Xcode]色の透明度を設定するには?

プログラミング・IT

どうも、ちょげ(@chogetarou)です。

UIKitで色の透明度を設定する方法を紹介します。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

UIKitで色の透明度を設定するには、withAlphaComponent子を使います。

まず、色にwithAlphaComponentを付与します。

そして、withAlphaComponentの引数に透明度を「0〜1」(0に近づくほど透明、1に近づくほど不透明)で指定します。

//透明度を「0〜1」(0に近いほど透明、1に近いほど不透明)
color.withAlphaComponent(/*透明度*/)

withAlphaComponentを使うことで、UIKitで色の透明度を設定することができます。

使用例

以下は、使用例です。

UIColor.red.withAlphaComponent(0.3) //透明度0.3

UIColor.green.withAlphaComponent(0.55) //透明度0.55

UIColor.blue.withAlphaComponent(0.8) //透明度0.8

コメント

タイトルとURLをコピーしました