Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
noppefoxwolf committed Mar 13, 2022
0 parents commit 04257a1
Show file tree
Hide file tree
Showing 39 changed files with 2,044 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
11 changes: 11 additions & 0 deletions Example.swiftpm/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 13 additions & 0 deletions Example.swiftpm/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Example.swiftpm/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 13 additions & 0 deletions Example.swiftpm/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import SwiftUI
import ColorPicker

struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
}
}
}
10 changes: 10 additions & 0 deletions Example.swiftpm/MyApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SwiftUI

@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
25 changes: 25 additions & 0 deletions Example.swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "SnapKit",
"repositoryURL": "https://github.com/SnapKit/SnapKit",
"state": {
"branch": null,
"revision": "d458564516e5676af9c70b4f4b2a9178294f1bc6",
"version": "5.0.1"
}
},
{
"package": "UIColorHexSwift",
"repositoryURL": "https://github.com/yeahdongcn/UIColor-Hex-Swift",
"state": {
"branch": null,
"revision": "4e0c1bc57c02fcb19c3b34ec5e6188383a95aa94",
"version": "5.1.8"
}
}
]
},
"version": 1
}
47 changes: 47 additions & 0 deletions Example.swiftpm/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// swift-tools-version: 5.5

// WARNING:
// This file is automatically generated.
// Do not edit it by hand because the contents will be replaced.

import PackageDescription
import AppleProductTypes

let package = Package(
name: "Example",
platforms: [
.iOS("15.2")
],
products: [
.iOSApplication(
name: "Example",
targets: ["AppModule"],
bundleIdentifier: "dev.noppe.Example",
teamIdentifier: "FBQ6Z8AF3U",
displayVersion: "1.0",
bundleVersion: "1",
iconAssetName: "AppIcon",
accentColorAssetName: "AccentColor",
supportedDeviceFamilies: [
.pad,
.phone
],
supportedInterfaceOrientations: [
.portrait,
.landscapeRight,
.landscapeLeft,
.portraitUpsideDown(.when(deviceFamilies: [.pad]))
]
)
],
dependencies: [
.package(path: "../")
],
targets: [
.executableTarget(
name: "AppModule",
dependencies: ["ColorPicker"],
path: "."
)
]
)
23 changes: 23 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"pins" : [
{
"identity" : "snapkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SnapKit/SnapKit",
"state" : {
"revision" : "d458564516e5676af9c70b4f4b2a9178294f1bc6",
"version" : "5.0.1"
}
},
{
"identity" : "uicolor-hex-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/yeahdongcn/UIColor-Hex-Swift",
"state" : {
"revision" : "4e0c1bc57c02fcb19c3b34ec5e6188383a95aa94",
"version" : "5.1.8"
}
}
],
"version" : 2
}
31 changes: 31 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// swift-tools-version: 5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ColorPicker",
platforms: [.iOS(.v15)],
products: [
.library(
name: "ColorPicker",
targets: ["ColorPicker"]
),
],
dependencies: [
.package(url: "https://github.com/SnapKit/SnapKit", from: "5.0.1"),
.package(url: "https://github.com/yeahdongcn/UIColor-Hex-Swift", from: "5.1.8"),
],
targets: [
.target(
name: "ColorPicker",
dependencies: [
"SnapKit",
.product(name: "UIColorHexSwift", package: "UIColor-Hex-Swift")
]
),
.testTarget(
name: "ColorPickerTests",
dependencies: ["ColorPicker"]),
]
)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ColorPicker

A description of this package.
32 changes: 32 additions & 0 deletions Sources/ColorPicker/Components/AddColorCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import UIKit
import SnapKit

class AddColorCell: UICollectionViewCell {
let backgroundColorView: UIView = .init(frame: .null)
let imageView: UIImageView = .init(frame: .null)

override init(frame: CGRect) {
super.init(frame: frame)

contentView.addSubview(backgroundColorView)
backgroundColorView.snp.makeConstraints { make in
make.center.equalToSuperview()
make.size.equalTo(30)
}
backgroundColorView.backgroundColor = .systemGray5
backgroundColorView.layer.cornerRadius = 15

backgroundColorView.addSubview(imageView)
imageView.snp.makeConstraints { make in
make.center.equalToSuperview()
make.size.equalTo(16)
}

imageView.image = UIImage(systemName: "plus")
imageView.tintColor = .systemGray2
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
50 changes: 50 additions & 0 deletions Sources/ColorPicker/Components/ColorCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import UIKit

class ColorCell: UICollectionViewCell {

override var isSelected: Bool {
didSet { setNeedsDisplay() }
}

override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .clear
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func draw(_ rect: CGRect) {
let context = UIGraphicsGetCurrentContext()!
if isSelected {
do { // inner ellipse
let size = CGSize(width: 17, height: 17)
context.setFillColor(tintColor.cgColor)
let origin = CGPoint(
x: (rect.width - size.width) / 2,
y: (rect.height - size.height) / 2
)
context.fillEllipse(in: CGRect(origin: origin, size: size))
}
do { // outline
let size = CGSize(width: 28, height: 28)
let origin = CGPoint(
x: (rect.width - size.width) / 2,
y: (rect.height - size.height) / 2
)
context.setStrokeColor(tintColor.cgColor)
context.setLineWidth(3)
context.strokeEllipse(in: CGRect(origin: origin, size: size))
}
} else {
let size = CGSize(width: 30, height: 30)
context.setFillColor(tintColor.cgColor)
let origin = CGPoint(
x: (rect.width - size.width) / 2,
y: (rect.height - size.height) / 2
)
context.fillEllipse(in: CGRect(origin: origin, size: size))
}
}
}
21 changes: 21 additions & 0 deletions Sources/ColorPicker/Components/HairlineView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import UIKit

class HairlineView: UIVisualEffectView {
init() {
let effect = UIVibrancyEffect(
blurEffect: UIBlurEffect(
style: .systemChromeMaterial
),
style: .separator
)
super.init(effect: effect)
contentView.backgroundColor = .systemBackground
self.snp.makeConstraints { make in
make.height.equalTo(1)
}
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
12 changes: 12 additions & 0 deletions Sources/ColorPicker/Extensions/UIColor+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import UIKit

extension UIColor {
var hsba: (hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) {
var hue: CGFloat = 0
var saturation: CGFloat = 0
var brightness: CGFloat = 0
var alpha: CGFloat = 0
getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha)
return (hue, saturation, brightness, alpha)
}
}
Loading

0 comments on commit 04257a1

Please sign in to comment.