ArnavMotwani/UnsplashSwiftUI
This SwiftUI package makes using the Unsplash API in an app simple and easy.
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)Package Metadata
Repository: ArnavMotwani/UnsplashSwiftUI
Homepage: https://www.arnv.net/packages
Stars: 8
Forks: 1
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: async, concurrency, ios, ios-swift, package, swift, swiftpackagemanager, swiftpackageregistry, swiftui
README: README.md