Day 48 - Share Restrictions & Shapes
Monday, February 28, 2022
Today, I worked on how to restrict users from sharing certain PDFs generated within apps. It’s weird to me that Apple produced many ways to restrict sharing of content, but then failed to give developers the ability to restrict some access. For example, you can prevent the app from showing copy, message, mail, etc. as share options, but you cannot prevent them from being able to Save to Files the generated PDF.
Also, I worked on the module one lesson three challenge in the Design course. I was happy to finally finish this. It’s weird drawing with shapes, but I can see how powerful creating these own graphics can be.
Challenge was to create your own shapes like this:
Here’s my solution code. It’s not exactly like the example given, but it was the only way I could get the two shapes to show up with different colors. Before, I tried making it with a single Path object, but then I was unable to change the colors (although, the shapes were more closely in the middle then).
I was surprised to find that the shape on the right was composed of two triangles as well. Always need to think about this stuff with drawing with shapes! So much can be made by re-using shapes.
//
// ContentView.swift
// PathsChallengeL3
//
// Created by Leone on 2/22/22.
//
import SwiftUI
struct ContentView: View {
var body: some View {
HStack(alignment: .center) {
// MARK: - Arrow
Path { path in
path.addLines(
[
CGPoint(x: 50, y: 225), // Top-left point
CGPoint(x: 150, y: 225), // Top-right
CGPoint(x: 230, y: 425), // Middle
CGPoint(x: 150, y: 625), // Bottom-right line
CGPoint(x: 50, y: 625), // Bottom line
CGPoint(x: 130, y: 425), // Bottom-left -> Middle
CGPoint(x: 50, y: 225) // Middle -> top-right
]
)
path.move(to: CGPoint(x: 250, y: 450))
// MARK: - Yellow Star
// path.addLines([
// CGPoint(x: 250, y: 385), // left-top
// CGPoint(x: 290, y: 385), // top-left
// CGPoint(x: 315, y: 345), // top-right edge
// CGPoint(x: 340, y: 385),
// CGPoint(x: 380, y: 385), // right-top
// CGPoint(x: 365, y: 425), // right star
// CGPoint(x: 380, y: 465),
// CGPoint(x: 340, y: 465), // bottom-right edge
// CGPoint(x: 315, y: 505), // bottom-middle right
// CGPoint(x: 290, y: 465), // bottom middle left
// CGPoint(x: 250, y: 465),
// CGPoint(x: 265, y: 425),
// CGPoint(x: 250, y: 385)
// ])
}
.foregroundColor(.blue)
.frame(width: 10)
Path { path in
path.addLines([
CGPoint(x: 250, y: 385), // left-top
CGPoint(x: 290, y: 385), // top-left
CGPoint(x: 315, y: 345), // top-right edge
CGPoint(x: 340, y: 385),
CGPoint(x: 380, y: 385), // right-top
CGPoint(x: 365, y: 425), // right star
CGPoint(x: 380, y: 465),
CGPoint(x: 340, y: 465), // bottom-right edge
CGPoint(x: 315, y: 505), // bottom-middle right
CGPoint(x: 290, y: 465), // bottom middle left
CGPoint(x: 250, y: 465),
CGPoint(x: 265, y: 425),
CGPoint(x: 250, y: 385)
])
}
.foregroundColor(.yellow)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}