create random icons and save to documents dir

This commit is contained in:
Trey t
2022-03-05 12:10:03 -06:00
parent d56e74053e
commit f41b1866a6
4 changed files with 85 additions and 28 deletions

View File

@@ -33,12 +33,12 @@ struct SettingsView: View {
showOnboardingButton
whyBackgroundMode
specialThanksCell
}
Group {
addTestDataCell
clearDB
randomIcons
if useCloudKit {
cloudKitStatus
@@ -220,6 +220,45 @@ struct SettingsView: View {
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
}
private var randomIcons: some View {
ZStack {
theme.currentTheme.secondaryBGColor
Button(action: {
var iconViews = [UIImage]()
for _ in 0...300 {
iconViews.append(
IconView(iconViewModel: IconViewModel(
backgroundImage: MoodImages.FontAwesome.icon(forMood: .great),
bgColor: Color.random(),
bgOverlayColor: Color.random(),
centerImage: MoodImages.FontAwesome.icon(forMood: .great),
innerColor: Color.random())
).asImage(size: CGSize(width: 1024, height: 1024)))
}
for (idx, image) in iconViews.enumerated() {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
var path = paths[0].appendingPathComponent("icons").path
path = path.appending("\(idx).jpg")
let url = URL(fileURLWithPath: path)
do {
try image.jpegData(compressionQuality: 1.0)?.write(to: url, options: .atomic)
print(url)
} catch {
print(error.localizedDescription)
}
}
}, label: {
Text("Create random icons")
.foregroundColor(theme.currentTheme.labelColor)
})
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
}
}
struct SettingsView_Previews: PreviewProvider {