HomeiOS Developmentios - The display screen of Canvas doesn't change coloration after I...

ios – The display screen of Canvas doesn’t change coloration after I use UIColor in SwiftUi or UIKit


Once I run ContentView.swift code as follows

import SwiftUI
import UIKit


class MainViewController: UIViewController{
    
  
    
    let collectionView: UICollectionView = {
        let format = UICollectionViewFlowLayout()
        let cv = UICollectionView(body: .zero, collectionViewLayout: format)
        let darkGrey = UIColor(hexString: "#757575")
        cv.backgroundColor = UIColor(hexString: "#757575")
        return cv
    }()
    
    override func viewDidLoad(){
        tremendous.viewDidLoad()
        
        view.addSubview(collectionView)
        collectionView.body = view.body
        
    }
    
    
}

extension UIColor {
    comfort init(hexString: String) {
        let hex = hexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
        var int = UInt64()
        Scanner(string: hex).scanHexInt64(&int)
        let a, r, g, b: UInt64
        change hex.depend {
        case 3: // RGB (12-bit)
            (a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
        case 6: // RGB (24-bit)
            (a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
        case 8: // ARGB (32-bit)
            (a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
        default:
            (a, r, g, b) = (255, 0, 0, 0)
        }
        self.init(crimson: CGFloat(r) / 255, inexperienced: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
    }
}


I get a white display screen on Canvas and I don`t perceive why my code doesn’t work since I constructed an
extesion UIColor. Any thought can be appreciated! Thanks in your persistence.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments