Bibi's DevLog ๐ค๐
UIColor extension ๋ณธ๋ฌธ
- UIColor extension์ผ๋ก ๊น๋ํ๊ฒ ํํํ๊ธฐ
- ๋ค์ํ UIColor ์ง์ ์์์ ์ต์คํ ์ ์ผ๋ก ๋ถ๋ฆฌํด ๋ณด๋ผ๊ณ ํด์ ์ฐพ์๋๋ฐ, ์ข์ ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ๋ค.
init : rgb ์ํ ๊ธฐ๋ณธ๊ฐ์ 1๋ก ์ง์ ํ๋ convenience init
customColor : ์ง์ ๋ ์์์ colorLiteral๋ก ํํ
//
// UIColorExtension.swift
// starbuckst
//
// Created by Bibi on 2022/05/11.
//
import UIKit
enum CustomColor {
case white
}
extension UIColor {
convenience init(red: Int, green: Int, blue: Int, a: Int = 1) {
self.init(
red: CGFloat(red) / 255.0,
green: CGFloat(green) / 255.0,
blue: CGFloat(blue) / 255.0,
alpha: CGFloat(a) / 255.0
)
}
static func customColor(_ name: CustomColor) -> UIColor {
switch name {
case .white: // return #colorLiteral()
return #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
}
}
}
'๐ฑ๐ iOS > Code Templates' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] Linked List - Singly Linked List ๊ตฌํ (0) | 2022.12.15 |
---|---|
[Swift] URL์์ ๋น๋๊ธฐ๋ก ์ด๋ฏธ์ง ๋ค์ด๋ก๋ ๋ฐ ์บ์ฑํ๊ธฐ - NSCache (0) | 2022.05.18 |
์ฝ๋๋ก UIView ๋ง๋ค๊ธฐ ๊ธฐ๋ณธ ํ ํ๋ฆฟ (0) | 2022.05.11 |
UIFont Extension - custom font (0) | 2022.05.11 |
[Swift] JSON API์ ๋คํธ์ํฌ ํต์ ํ๊ธฐ - URLSession, JSONConverter (0) | 2022.04.29 |