Answers for "ui image properties swift"

1

uiimage swift src url

let imageCache = NSCache<AnyObject, AnyObject>()

class CustomImageView: UIImageView {
    
    var ImageUrlString: URL?
    
    func setImage(from url: URL, contentMode mode: UIViewContentMode = .scaleAspectFit) {
        contentMode = mode
        ImageUrlString = url
        if let imageFromCache = imageCache.object(forKey: url as AnyObject) {
            self.image = imageFromCache as? UIImage
            return
        }
        
        URLSession.shared.dataTask(with: url) { data, response, error in
            guard
                let httpURLResponse = response as? HTTPURLResponse, httpURLResponse.statusCode == 200,
                let mimeType = response?.mimeType, mimeType.hasPrefix("image"),
                let data = data, error == nil,
                let imageToCache = UIImage(data: data)
                else { return }
            DispatchQueue.main.async() {
                if self.ImageUrlString == url {
                    self.image = imageToCache
                }
                imageCache.setObject(imageToCache, forKey: url as AnyObject)
            }
        }.resume()
    }
    func setImage(from link: String, contentMode mode: UIViewContentMode = .scaleAspectFit) {
        guard let url = URL(string: link) else { return }
        setImage(from: url, contentMode: mode)
    }
}
Posted by: Guest on April-01-2020
0

swiftui system image

//The system image uses the sf symbols app
//Make sure you download the sf symbols app first as it wlll be useful later
// https://developer.apple.com/sf-symbols/
//(NOTE THAT IS YOUR macOS IS NOT 12, PLEASE DOWNLOAD THE 11.x VERSION AND NOT THE BETA ONE)

//Basically, these sf symbols are made by apple and are usually used in its apps
//To use these, you first need to find out the name of the sf symbol 
//(In the sf symbols app, or search it up online)
//Then, we can use the systemName argument in the image struct (swiftui)

Image(systemName: <String>)

//The string in this case is the name of the sf symbol you wish to put
//Examples include "chevron" ->

Image(systemName: "chevron")
Posted by: Guest on August-20-2021

Code answers related to "Swift"

Browse Popular Code Answers by Language