Set up example collection view
This commit is contained in:
parent
123f6c7443
commit
57dcb6038d
|
@ -9,11 +9,10 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
F4EC51C421D33B6900DED569 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4EC51C321D33B6900DED569 /* AppDelegate.swift */; };
|
||||
F4EC51C621D33B6900DED569 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4EC51C521D33B6900DED569 /* ViewController.swift */; };
|
||||
F4EC51C921D33B6900DED569 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F4EC51C721D33B6900DED569 /* Main.storyboard */; };
|
||||
F4EC51CB21D33B6B00DED569 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F4EC51CA21D33B6B00DED569 /* Assets.xcassets */; };
|
||||
F4EC51CE21D33B6B00DED569 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F4EC51CC21D33B6B00DED569 /* LaunchScreen.storyboard */; };
|
||||
F4EC51D921D33B6B00DED569 /* ImagesExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4EC51D821D33B6B00DED569 /* ImagesExampleTests.swift */; };
|
||||
F4EC51F021D33C1800DED569 /* PlaceholderKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4EC51E921D33B7D00DED569 /* PlaceholderKit.framework */; };
|
||||
F4EC51F721D36DE100DED569 /* PlaceholderKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F4EC51E921D33B7D00DED569 /* PlaceholderKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
@ -38,13 +37,33 @@
|
|||
remoteGlobalIDString = F444B67921C104460042E6F2;
|
||||
remoteInfo = PlaceholderKitTests;
|
||||
};
|
||||
F4EC51F821D36DE100DED569 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = F4EC51E321D33B7D00DED569 /* PlaceholderKit.xcodeproj */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = F444B66F21C104460042E6F2;
|
||||
remoteInfo = PlaceholderKit;
|
||||
};
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
F4EC51FA21D36DE200DED569 /* Embed Frameworks */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
F4EC51F721D36DE100DED569 /* PlaceholderKit.framework in Embed Frameworks */,
|
||||
);
|
||||
name = "Embed Frameworks";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
F4EC51C021D33B6900DED569 /* ImagesExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ImagesExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
F4EC51C321D33B6900DED569 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
F4EC51C521D33B6900DED569 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||
F4EC51C821D33B6900DED569 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
F4EC51CA21D33B6B00DED569 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
F4EC51CD21D33B6B00DED569 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
F4EC51CF21D33B6B00DED569 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
|
@ -59,7 +78,6 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
F4EC51F021D33C1800DED569 /* PlaceholderKit.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -98,7 +116,6 @@
|
|||
children = (
|
||||
F4EC51C321D33B6900DED569 /* AppDelegate.swift */,
|
||||
F4EC51C521D33B6900DED569 /* ViewController.swift */,
|
||||
F4EC51C721D33B6900DED569 /* Main.storyboard */,
|
||||
F4EC51CA21D33B6B00DED569 /* Assets.xcassets */,
|
||||
F4EC51CC21D33B6B00DED569 /* LaunchScreen.storyboard */,
|
||||
F4EC51CF21D33B6B00DED569 /* Info.plist */,
|
||||
|
@ -141,10 +158,12 @@
|
|||
F4EC51BC21D33B6900DED569 /* Sources */,
|
||||
F4EC51BD21D33B6900DED569 /* Frameworks */,
|
||||
F4EC51BE21D33B6900DED569 /* Resources */,
|
||||
F4EC51FA21D36DE200DED569 /* Embed Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
F4EC51F921D36DE100DED569 /* PBXTargetDependency */,
|
||||
);
|
||||
name = ImagesExample;
|
||||
productName = ImagesExample;
|
||||
|
@ -237,7 +256,6 @@
|
|||
files = (
|
||||
F4EC51CE21D33B6B00DED569 /* LaunchScreen.storyboard in Resources */,
|
||||
F4EC51CB21D33B6B00DED569 /* Assets.xcassets in Resources */,
|
||||
F4EC51C921D33B6900DED569 /* Main.storyboard in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -276,17 +294,14 @@
|
|||
target = F4EC51BF21D33B6900DED569 /* ImagesExample */;
|
||||
targetProxy = F4EC51D521D33B6B00DED569 /* PBXContainerItemProxy */;
|
||||
};
|
||||
F4EC51F921D36DE100DED569 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
name = PlaceholderKit;
|
||||
targetProxy = F4EC51F821D36DE100DED569 /* PBXContainerItemProxy */;
|
||||
};
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
F4EC51C721D33B6900DED569 /* Main.storyboard */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
F4EC51C821D33B6900DED569 /* Base */,
|
||||
);
|
||||
name = Main.storyboard;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
F4EC51CC21D33B6B00DED569 /* LaunchScreen.storyboard */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
|
@ -417,6 +432,7 @@
|
|||
F4EC51DE21D33B6B00DED569 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = T3LQ95726F;
|
||||
|
@ -435,6 +451,7 @@
|
|||
F4EC51DF21D33B6B00DED569 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
DEVELOPMENT_TEAM = T3LQ95726F;
|
||||
|
|
|
@ -16,6 +16,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
window = UIWindow(frame: UIScreen.main.bounds)
|
||||
let controller = ViewController()
|
||||
window?.rootViewController = controller
|
||||
window?.makeKeyAndVisible()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="tne-QT-ifu">
|
||||
<objects>
|
||||
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
|
@ -22,8 +22,6 @@
|
|||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
|
|
|
@ -10,16 +10,105 @@ import UIKit
|
|||
import PlaceholderKit
|
||||
|
||||
class ViewController: UIViewController {
|
||||
var sampleImagesCollectionViewController: SampleImagesCollectionViewController?
|
||||
lazy var images: [UIImage] = {
|
||||
return [
|
||||
PlaceholderBuilder().coloredBackground(color: .red, size: CGSize(width: 100, height: 100)),
|
||||
PlaceholderBuilder().coloredBackground(color: .blue, size: CGSize(width: 100, height: 100)),
|
||||
PlaceholderBuilder().coloredBackground(color: .green, size: CGSize(width: 100, height: 100)),
|
||||
PlaceholderBuilder().coloredBackground(color: .yellow, size: CGSize(width: 100, height: 100)),
|
||||
].compactMap({$0})
|
||||
}()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
let settings = PlaceholderSettings(size: CGSize(width: 320, height: 640),
|
||||
background: .solidColor(UIColor.red),
|
||||
showDimensionAsText: true,
|
||||
convertDimensionToAspectRatio: false)
|
||||
let factory = PlaceholderFactory(settings: settings)
|
||||
let image = factory.createPlaceholder()
|
||||
print(image)
|
||||
view.backgroundColor = UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1.0)
|
||||
setupCollectionViewController()
|
||||
}
|
||||
|
||||
func setupCollectionViewController() {
|
||||
let controller = SampleImagesCollectionViewController(data: images)
|
||||
guard let collectionView = controller.view else { return }
|
||||
|
||||
collectionView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(collectionView)
|
||||
sampleImagesCollectionViewController = controller
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
collectionView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 30),
|
||||
collectionView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -30),
|
||||
collectionView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -30),
|
||||
collectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 30)
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
class SampleImagesCollectionViewController: UICollectionViewController {
|
||||
let data: [UIImage]
|
||||
|
||||
init(data: [UIImage]) {
|
||||
self.data = data
|
||||
let layout = UICollectionViewFlowLayout()
|
||||
layout.itemSize = CGSize(width: 200, height: 200)
|
||||
layout.scrollDirection = .vertical
|
||||
|
||||
super.init(collectionViewLayout: layout)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
collectionView.register(SampleImageCollectionViewCell.self, forCellWithReuseIdentifier: SampleImageCollectionViewCell.reuseIdentifier)
|
||||
collectionView.backgroundColor = .clear
|
||||
}
|
||||
|
||||
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
||||
return data.count
|
||||
}
|
||||
|
||||
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
||||
|
||||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SampleImageCollectionViewCell.reuseIdentifier,
|
||||
for: indexPath)
|
||||
|
||||
guard let castedCell = cell as? SampleImageCollectionViewCell else {
|
||||
return cell
|
||||
}
|
||||
|
||||
castedCell.imageView.image = data[indexPath.row]
|
||||
|
||||
return castedCell
|
||||
}
|
||||
}
|
||||
|
||||
class SampleImageCollectionViewCell: UICollectionViewCell {
|
||||
static let reuseIdentifier = "SampleImagesCell"
|
||||
|
||||
lazy var imageView: UIImageView = {
|
||||
let imageView = UIImageView()
|
||||
imageView.translatesAutoresizingMaskIntoConstraints = false
|
||||
imageView.contentMode = .scaleAspectFit
|
||||
return imageView
|
||||
}()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(imageView)
|
||||
NSLayoutConstraint.activate([
|
||||
imageView.topAnchor.constraint(equalTo: topAnchor),
|
||||
imageView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
||||
imageView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||||
imageView.trailingAnchor.constraint(equalTo: trailingAnchor)
|
||||
])
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -384,8 +384,8 @@
|
|||
baseConfigurationReference = F444B68D21C104900042E6F2 /* Universal-Framework-Target.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CODE_SIGN_IDENTITY = "Mac Developer";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DEVELOPMENT_TEAM = T3LQ95726F;
|
||||
|
@ -395,6 +395,7 @@
|
|||
FRAMEWORK_VERSION = A;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Framework-Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
|
@ -402,6 +403,7 @@
|
|||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.shaopinglee.PlaceholderKit;
|
||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SDKROOT = "";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
|
@ -414,8 +416,8 @@
|
|||
baseConfigurationReference = F444B68D21C104900042E6F2 /* Universal-Framework-Target.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CODE_SIGN_IDENTITY = "Mac Developer";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEFINES_MODULE = YES;
|
||||
DEVELOPMENT_TEAM = T3LQ95726F;
|
||||
|
@ -425,6 +427,7 @@
|
|||
FRAMEWORK_VERSION = A;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/Framework-Info.plist";
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
|
@ -432,6 +435,7 @@
|
|||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.shaopinglee.PlaceholderKit;
|
||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SDKROOT = "";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 4.2;
|
||||
|
@ -444,8 +448,8 @@
|
|||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CODE_SIGN_IDENTITY = "Mac Developer";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = T3LQ95726F;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/FrameworkTests-Info.plist";
|
||||
|
@ -456,6 +460,7 @@
|
|||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.shaopinglee.PlaceholderKitTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 4.2;
|
||||
};
|
||||
|
@ -467,8 +472,8 @@
|
|||
buildSettings = {
|
||||
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CODE_SIGN_IDENTITY = "Mac Developer";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEVELOPMENT_TEAM = T3LQ95726F;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/Supporting Files/FrameworkTests-Info.plist";
|
||||
|
@ -479,6 +484,7 @@
|
|||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.shaopinglee.PlaceholderKitTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_VERSION = 4.2;
|
||||
};
|
||||
name = Release;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
import AppKit
|
||||
|
||||
extension NSImage {
|
||||
static func createPlaceholder(withColor color: NSColor, size: CGSize) -> NSImage? {
|
||||
static func image(withColor color: NSColor, size: CGSize) -> NSImage? {
|
||||
let image = NSImage(size: size)
|
||||
image.lockFocus()
|
||||
color.drawSwatch(in: NSMakeRect(0, 0, size.width, size.height))
|
||||
|
|
|
@ -16,21 +16,26 @@ public typealias Color = UIColor
|
|||
public typealias Image = UIImage
|
||||
#endif
|
||||
|
||||
public struct PlaceholderFactory {
|
||||
let settings: PlaceholderSettings
|
||||
public struct Placeholder {
|
||||
let size: CGSize
|
||||
let backgroundStyle: BackgroundStyle
|
||||
|
||||
public func createPlaceholder() -> Image? {
|
||||
switch settings.background {
|
||||
case .solidColor(let color):
|
||||
return Image.createPlaceholder(withColor: color, size: settings.size)
|
||||
case .image:
|
||||
return nil
|
||||
}
|
||||
public init(size: CGSize, backgroundStyle: BackgroundStyle) {
|
||||
self.size = size
|
||||
self.backgroundStyle = backgroundStyle
|
||||
}
|
||||
}
|
||||
|
||||
public struct PlaceholderBuilder {
|
||||
public func coloredBackground(color: UIColor, size: CGSize) -> Image? {
|
||||
return Image.image(withColor: color, size: size)
|
||||
}
|
||||
|
||||
public init(settings: PlaceholderSettings) {
|
||||
self.settings = settings
|
||||
public func imageBackground(image: UIImage, size: CGSize, tiled: Bool = false) -> Image? {
|
||||
return nil
|
||||
}
|
||||
|
||||
public init() {}
|
||||
}
|
||||
|
||||
public struct PlaceholderSettings {
|
||||
|
|
|
@ -10,16 +10,14 @@
|
|||
import UIKit
|
||||
|
||||
extension UIImage {
|
||||
static func createPlaceholder(withColor color: UIColor, size: CGSize) -> UIImage? {
|
||||
let rect = CGRect(origin: .zero, size: size)
|
||||
UIGraphicsBeginImageContextWithOptions(rect.size, false, 1.0)
|
||||
color.setFill()
|
||||
UIRectFill(rect)
|
||||
let image = UIGraphicsGetImageFromCurrentImageContext()
|
||||
UIGraphicsEndImageContext()
|
||||
static func image(withColor color: UIColor, size: CGSize) -> UIImage? {
|
||||
let renderer = UIGraphicsImageRenderer(size: size)
|
||||
let image = renderer.image { context in
|
||||
color.setFill()
|
||||
context.fill(CGRect(origin: .zero, size: size))
|
||||
}
|
||||
|
||||
guard let cgImage = image?.cgImage else { return nil }
|
||||
return UIImage(cgImage: cgImage)
|
||||
return image
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
IPHONEOS_DEPLOYMENT_TARGET = 8.0
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 10.0
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11
|
||||
|
|
Loading…
Reference in New Issue