스플래시 페이지 추가
This commit is contained in:
40
SodaLive/Sources/Extensions/ColorExtension.swift
Normal file
40
SodaLive/Sources/Extensions/ColorExtension.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// ColorExtension.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/09.
|
||||
//
|
||||
// https://seons-dev.tistory.com/174
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
extension Color {
|
||||
init(hex: String) {
|
||||
let scanner = Scanner(string: hex)
|
||||
_ = scanner.scanString("#")
|
||||
|
||||
var rgb: UInt64 = 0
|
||||
scanner.scanHexInt64(&rgb)
|
||||
|
||||
let r = Double((rgb >> 16) & 0xFF) / 255.0
|
||||
let g = Double((rgb >> 8) & 0xFF) / 255.0
|
||||
let b = Double((rgb >> 0) & 0xFF) / 255.0
|
||||
self.init(red: r, green: g, blue: b)
|
||||
}
|
||||
}
|
||||
|
||||
extension UIColor {
|
||||
convenience init(hex: String, alpha: CGFloat = 1.0) {
|
||||
let scanner = Scanner(string: hex)
|
||||
_ = scanner.scanString("#")
|
||||
|
||||
var rgb: UInt64 = 0
|
||||
scanner.scanHexInt64(&rgb)
|
||||
|
||||
let r = Double((rgb >> 16) & 0xFF) / 255.0
|
||||
let g = Double((rgb >> 8) & 0xFF) / 255.0
|
||||
let b = Double((rgb >> 0) & 0xFF) / 255.0
|
||||
self.init(red: r, green: g, blue: b, alpha: alpha)
|
||||
}
|
||||
}
|
21
SodaLive/Sources/Extensions/DateExtension.swift
Normal file
21
SodaLive/Sources/Extensions/DateExtension.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// DateExtension.swift
|
||||
// yozm
|
||||
//
|
||||
// Created by klaus on 2022/05/27.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Date {
|
||||
func convertDateFormat(dateFormat: String = "yyyy.MM.dd") -> String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = dateFormat
|
||||
formatter.locale = Locale(identifier: "ko")
|
||||
return formatter.string(from: self)
|
||||
}
|
||||
|
||||
func currentTimeMillis() -> Int64 {
|
||||
return Int64(self.timeIntervalSince1970 * 1000)
|
||||
}
|
||||
}
|
32
SodaLive/Sources/Extensions/IntExtension.swift
Normal file
32
SodaLive/Sources/Extensions/IntExtension.swift
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// IntExtension.swift
|
||||
// yozm
|
||||
//
|
||||
// Created by klaus on 2022/06/21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Int64 {
|
||||
func durationText() -> String {
|
||||
let duration = self
|
||||
|
||||
let convertedTime = Int(duration / 1000)
|
||||
let hour = Int(convertedTime / 3600)
|
||||
let minute = Int(convertedTime / 60) % 60
|
||||
let second = Int(convertedTime % 60)
|
||||
|
||||
// update UI
|
||||
var timeText = [String]()
|
||||
|
||||
if hour > 0 {
|
||||
timeText.append(String(hour))
|
||||
timeText.append(String(format: "%02d", minute))
|
||||
} else {
|
||||
timeText.append(String(format: "%02d", minute))
|
||||
timeText.append(String(format: "%02d", second))
|
||||
}
|
||||
|
||||
return timeText.joined(separator: ":")
|
||||
}
|
||||
}
|
43
SodaLive/Sources/Extensions/StringExtension.swift
Normal file
43
SodaLive/Sources/Extensions/StringExtension.swift
Normal file
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// StringExtension.swift
|
||||
// yozm
|
||||
//
|
||||
// Created by klaus on 2022/06/03.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Optional where Wrapped == String {
|
||||
func isNullOrBlank() -> Bool {
|
||||
return self == nil || self!.trimmingCharacters(in: .whitespaces).isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
func convertDateFormat(from: String, to: String) -> String {
|
||||
let fromFormatter = DateFormatter()
|
||||
fromFormatter.dateFormat = from
|
||||
fromFormatter.timeZone = TimeZone(identifier: TimeZone.current.identifier)
|
||||
|
||||
if let date = fromFormatter.date(from: self) {
|
||||
return date.convertDateFormat(dateFormat: to)
|
||||
} else {
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
func substring(from: Int, to: Int) -> String {
|
||||
guard from < count, to >= 0, to - from >= 0 else {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Index 값 획득
|
||||
let startIndex = index(self.startIndex, offsetBy: from)
|
||||
let endIndex = index(self.startIndex, offsetBy: to + 1) // '+1'이 있는 이유: endIndex는 문자열의 마지막 그 다음을 가리키기 때문
|
||||
|
||||
// 파싱
|
||||
return String(self[startIndex ..< endIndex])
|
||||
|
||||
// 출처 - https://ios-development.tistory.com/379
|
||||
}
|
||||
}
|
72
SodaLive/Sources/Extensions/UserDefaultsExtension.swift
Normal file
72
SodaLive/Sources/Extensions/UserDefaultsExtension.swift
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// UserDefaultsExtension.swift
|
||||
// yozm
|
||||
//
|
||||
// Created by klaus on 2022/05/20.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum UserDefaultsKey: String, CaseIterable {
|
||||
case auth
|
||||
case role
|
||||
case coin
|
||||
case token
|
||||
case email
|
||||
case userId
|
||||
case nickname
|
||||
case pushToken
|
||||
case profileImage
|
||||
case voipPushToken
|
||||
case devicePushToken
|
||||
case isContentPlayLoop
|
||||
case isFollowedCreatorLive
|
||||
case isViewedOnboardingView
|
||||
case notShowingEventPopupId
|
||||
}
|
||||
|
||||
extension UserDefaults {
|
||||
static func set(_ value: Bool, forKey key: UserDefaultsKey) {
|
||||
let key = key.rawValue
|
||||
UserDefaults.standard.set(value, forKey: key)
|
||||
}
|
||||
|
||||
static func bool(forKey key: UserDefaultsKey) -> Bool {
|
||||
let key = key.rawValue
|
||||
return UserDefaults.standard.bool(forKey: key)
|
||||
}
|
||||
|
||||
static func set(_ value: String, forKey key: UserDefaultsKey) {
|
||||
let key = key.rawValue
|
||||
UserDefaults.standard.set(value, forKey: key)
|
||||
}
|
||||
|
||||
static func string(forKey key: UserDefaultsKey) -> String {
|
||||
let key = key.rawValue
|
||||
return UserDefaults.standard.string(forKey: key) ?? ""
|
||||
}
|
||||
|
||||
static func set(_ value: Int, forKey key: UserDefaultsKey) {
|
||||
let key = key.rawValue
|
||||
UserDefaults.standard.set(value, forKey: key)
|
||||
}
|
||||
|
||||
static func int(forKey key: UserDefaultsKey) -> Int {
|
||||
let key = key.rawValue
|
||||
return UserDefaults.standard.integer(forKey: key)
|
||||
}
|
||||
|
||||
static func set(_ value: Data, forKey key: UserDefaultsKey) {
|
||||
let key = key.rawValue
|
||||
UserDefaults.standard.set(value, forKey: key)
|
||||
}
|
||||
|
||||
static func data(forKey key: UserDefaultsKey) -> Data? {
|
||||
let key = key.rawValue
|
||||
return UserDefaults.standard.data(forKey: key)
|
||||
}
|
||||
|
||||
static func reset() {
|
||||
UserDefaultsKey.allCases.forEach { UserDefaults.standard.removeObject(forKey: $0.rawValue) }
|
||||
}
|
||||
}
|
49
SodaLive/Sources/Extensions/ViewExtension.swift
Normal file
49
SodaLive/Sources/Extensions/ViewExtension.swift
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// ViewExtension.swift
|
||||
// yozm
|
||||
//
|
||||
// Created by klaus on 2022/05/19.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
extension View {
|
||||
func screenSize() -> CGRect {
|
||||
return UIScreen.main.bounds
|
||||
}
|
||||
|
||||
// 출처 - https://stackoverflow.com/a/58606176
|
||||
func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
|
||||
clipShape( RoundedCorner(radius: radius, corners: corners) )
|
||||
}
|
||||
|
||||
func hideKeyboard() {
|
||||
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
|
||||
}
|
||||
|
||||
/// A backwards compatible wrapper for iOS 14 `onChange`
|
||||
@ViewBuilder func valueChanged<T: Equatable>(value: T, onChange: @escaping (T) -> Void) -> some View {
|
||||
if #available(iOS 14.0, *) {
|
||||
self.onChange(of: value, perform: onChange)
|
||||
} else {
|
||||
self.onReceive(Just(value)) { (value) in
|
||||
onChange(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder func scrollContentBackgroundHidden() -> some View {
|
||||
if #available(iOS 16.0, *) {
|
||||
self.scrollContentBackground(.hidden)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder func progressColor(color: Color) -> some View {
|
||||
if #available(iOS 16.0, *) {
|
||||
self.tint(color)
|
||||
} else {
|
||||
self.accentColor(color)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user