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

Swift extension集

Last updated at Posted at 2021-01-05

はじめに

何気なく調べたりして使っていると、また使おうとした時にどう書くんだっけな・・・
ということがよくあるので忘備録として記録します。

ダークモードかどうかをBoolで返す

extension

extension UITraitCollection {
  
  public static var isDarkMode: Bool {
    if #available(iOS 13, *), current.userInterfaceStyle == .dark {
      return true
    }
    return false
  }
}

使い方

    if UITraitCollection.isDarkMode {
    //trueの場合
    }else{
    //falseの場合
    }

UIColorをRGB(0~255)で指定する

extension

extension UIColor {

  static func rgb(red: CGFloat,green: CGFloat,blue: CGFloat,alpha: CGFloat) -> UIColor {

    return self.init(red: red / 255, green: green / 255, blue: blue / 255,alpha: alpha)

  }
}

使い方

    let color:UIColor = .rgb(red: 10, green: 10, blue: 10, alpha: 1.0)
0
1
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
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?