UnsplashSwiftUI

2.1.0

This SwiftUI package makes using the Unsplash API in an app simple and easy.
ArnavMotwani/UnsplashSwiftUI

What's New

v2.1.0

2022-01-30T23:08:57Z

This version allows you to call the UnsplashRandom view multiple times.

UnsplashSwiftUI

This SwiftUI package makes using the Unsplash API in an app simple and easy.

Call the view and apply modifiers to it like you would with any other view. The package will fetch the image metadata from the API and it will load the remote image asynchronously. The view also has a text in the bottom left corner crediting the photographer as well as hotlinking to the image on Unsplash (A requirement while using the API).

Requirements:

The package is only compatible with iOS 15 and iPadOS 15 for now. Previous releases of this package support older OS versions however this release uses the new concurrency features as well as the new AsyncImage View

The package requires a Access Key (Client ID) for the Unsplash API. You can get one from the Unsplash Developers page. You'll need to register your app there and you will be Rate Limited (limited number of API requests per hour) until you apply for a high-volume application (refer to the Unsplash Developers page for more details)

Disclamer: I have not attempted applying for a high-volume application using this library as of yet. I believe that I have met all the requirements of the API and you should have no problem with it however I am not completely sure.

Installation:

In Xcode go to File -> Add Packages and paste in the repo's url: https://github.com/ArnavMotwani/UnsplashSwiftUI.git then either select a version or the main branch (I will update the main branch more frequently with minor changes, while the version number will only increase with significant changes)

Usage:

Import the package into the file with import UnsplashSwiftUI then call the UnsplashRandom view wherever you want.

Examples:

import SwiftUI
import UnsplashSwiftUI

struct UnsplashRandomTest: View {
    var body: some View {
        UnsplashRandom(clientId: "YOUR_ACCESS_KEY")
    }
}

struct UnsplashRandomTest_Previews: PreviewProvider {
    static var previews: some View {
        UnsplashRandomTest()
    }
}
import SwiftUI
import UnsplashSwiftUI

struct UnsplashRandomTest: View {
    var body: some View {
        UnsplashRandom(clientId: "YOUR_ACCESS_KEY")
        .padding(25)
    }
}

struct UnsplashRandomTest_Previews: PreviewProvider {
    static var previews: some View {
        UnsplashRandomTest()
    }
}
import SwiftUI
import UnsplashSwiftUI

struct UnsplashRandomTest: View {
    var body: some View {
        UnsplashRandom(clientId: "YOUR_ACCESS_KEY")
        .clipShape(RoundedRectangle(cornerRadius: 10))
    }
}

struct UnsplashRandomTest_Previews: PreviewProvider {
    static var previews: some View {
        UnsplashRandomTest()
    }
}

Customizations:

Parameter Optional? Type Description Default
clientId No String Client ID from the Unsplash Developer page -
orientation Yes Orientations Filter by photo orientation. (Valid values: .landscape, .portrait, .squarish, .none) -
query Yes String Limit selection to photos matching a search term. -
textColor Yes Color Color of the text hotlinked to image on Unsplash Color.white
textBackgroundColor Yes Color Color of text background (opacity set to 0.2 automatically) Color.black
aspectRatio Yes ContentMode Choose whether the image fits or fills the container ContentMode.fit

Examples:

orientation

    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", orientation: .landscape)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", orientation: .portrait)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", orientation: .squarish)

query

    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", query: "trees")
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", query: "landscapes")
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", query: "space")

textColor

    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textColor: .black)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textColor: .blue)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textColor: .primary)

textBackgroundColor

    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textBackgroundColor: .white)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textBackgroundColor: .blue)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", textBackgroundColor: .primary)

aspectRatio

    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", aspectRatio: .fit)
    
    UnsplashRandom(clientId: "YOUR_ACCESS_KEY", aspectRatio: .fill)

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 15:17:50 GMT-0900 (Hawaii-Aleutian Daylight Time)