content mode
This commit is contained in:
parent
347928a9b6
commit
68bf45f583
@ -27,6 +27,7 @@
|
||||
012A88F123985E0100FE3DA1 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012A88F023985E0100FE3DA1 /* Color.swift */; };
|
||||
012CA99A2384A687003F810F /* MFTextField+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */; };
|
||||
012CA99E2385A2D3003F810F /* MFView+ModelExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */; };
|
||||
013F801923FB4A8E00AD8013 /* UIContentMode+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 013F801823FB4A8E00AD8013 /* UIContentMode+Extension.swift */; };
|
||||
014AA72423C501E2006F3E93 /* MoleculeContainerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */; };
|
||||
014AA72523C501E2006F3E93 /* ContainerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014AA72223C501E2006F3E93 /* ContainerModel.swift */; };
|
||||
014AA72623C501E2006F3E93 /* ContainerModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 014AA72323C501E2006F3E93 /* ContainerModelProtocol.swift */; };
|
||||
@ -359,6 +360,7 @@
|
||||
012A88F023985E0100FE3DA1 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
|
||||
012CA9992384A687003F810F /* MFTextField+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFTextField+ModelExtension.swift"; sourceTree = "<group>"; };
|
||||
012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MFView+ModelExtension.swift"; sourceTree = "<group>"; };
|
||||
013F801823FB4A8E00AD8013 /* UIContentMode+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIContentMode+Extension.swift"; sourceTree = "<group>"; };
|
||||
014AA72123C501E2006F3E93 /* MoleculeContainerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoleculeContainerModel.swift; sourceTree = "<group>"; };
|
||||
014AA72223C501E2006F3E93 /* ContainerModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerModel.swift; sourceTree = "<group>"; };
|
||||
014AA72323C501E2006F3E93 /* ContainerModelProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerModelProtocol.swift; sourceTree = "<group>"; };
|
||||
@ -1142,6 +1144,7 @@
|
||||
D29DF11021E6805F003B2FB9 /* Categories */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
013F801823FB4A8E00AD8013 /* UIContentMode+Extension.swift */,
|
||||
D29DF11121E6805F003B2FB9 /* UIColor+MFConvenience.h */,
|
||||
D29DF11321E6805F003B2FB9 /* UIColor+MFConvenience.m */,
|
||||
D29DF11221E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.h */,
|
||||
@ -1801,6 +1804,7 @@
|
||||
943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */,
|
||||
D29DF2AA21E7B2F9003B2FB9 /* MVMCoreUIConstants.m in Sources */,
|
||||
948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */,
|
||||
013F801923FB4A8E00AD8013 /* UIContentMode+Extension.swift in Sources */,
|
||||
D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */,
|
||||
D2E2A9A323E096B1000B42E6 /* DisableableModelProtocol.swift in Sources */,
|
||||
D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */,
|
||||
|
||||
@ -17,23 +17,7 @@ import Foundation
|
||||
public var imageFormat: String?
|
||||
public var width: CGFloat?
|
||||
public var height: CGFloat?
|
||||
public var contentMode: ContentMode?
|
||||
|
||||
public enum ContentMode : String, Codable {
|
||||
case scaleToFill
|
||||
case scaleAspectFit // contents scaled to fit with fixed aspect. remainder is transparent
|
||||
case scaleAspectFill // contents scaled to fill with fixed aspect. some portion of content may be clipped.
|
||||
case redraw // redraw on bounds change (calls -setNeedsDisplay)
|
||||
case center // contents remain same size. positioned adjusted.
|
||||
case top
|
||||
case bottom
|
||||
case left
|
||||
case right
|
||||
case topLeft
|
||||
case topRight
|
||||
case bottomLeft
|
||||
case bottomRight
|
||||
}
|
||||
public var contentMode: UIView.ContentMode?
|
||||
|
||||
public init(image: String) {
|
||||
self.image = image
|
||||
|
||||
@ -232,54 +232,10 @@ import UIKit
|
||||
imageView.animatedImage = nil
|
||||
loadImage(withName: imageModel.image, format: imageModel.imageFormat, width: width as NSNumber?, height: height as NSNumber?, customFallbackImage: imageModel.fallbackImage)
|
||||
}
|
||||
setContentMode(imageModel)
|
||||
}
|
||||
|
||||
func setContentMode(_ model: ImageViewModel?) {
|
||||
switch model?.contentMode {
|
||||
case .scaleToFill:
|
||||
imageView.contentMode = .scaleToFill
|
||||
break
|
||||
case .scaleAspectFit:
|
||||
imageView.contentMode = .scaleAspectFit
|
||||
break
|
||||
case .scaleAspectFill:
|
||||
imageView.contentMode = .scaleAspectFill
|
||||
break
|
||||
case .redraw:
|
||||
imageView.contentMode = .redraw
|
||||
break
|
||||
case .center:
|
||||
imageView.contentMode = .center
|
||||
break
|
||||
case .top:
|
||||
imageView.contentMode = .top
|
||||
break
|
||||
case .bottom:
|
||||
imageView.contentMode = .bottom
|
||||
break
|
||||
case .left:
|
||||
imageView.contentMode = .left
|
||||
break
|
||||
case .right:
|
||||
imageView.contentMode = .right
|
||||
break
|
||||
case .topLeft:
|
||||
imageView.contentMode = .topLeft
|
||||
break
|
||||
case .topRight:
|
||||
imageView.contentMode = .topRight
|
||||
break
|
||||
case .bottomLeft:
|
||||
imageView.contentMode = .bottomLeft
|
||||
break
|
||||
case .bottomRight:
|
||||
imageView.contentMode = .bottomRight
|
||||
break
|
||||
default:
|
||||
break
|
||||
if let contentMode = imageModel.contentMode {
|
||||
imageView.contentMode = contentMode
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtocol functions
|
||||
|
||||
98
MVMCoreUI/Categories/UIContentMode+Extension.swift
Normal file
98
MVMCoreUI/Categories/UIContentMode+Extension.swift
Normal file
@ -0,0 +1,98 @@
|
||||
//
|
||||
// UIContentMode+Extension.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 2/17/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum ContentModeError: Error {
|
||||
case notAContentMode
|
||||
}
|
||||
|
||||
extension UIView.ContentMode: RawRepresentable {
|
||||
|
||||
init?(rawValue: String) {
|
||||
switch rawValue {
|
||||
case "scaleToFill":
|
||||
self = .scaleToFill
|
||||
case "scaleAspectFit":
|
||||
self = .scaleAspectFit
|
||||
case "scaleAspectFill":
|
||||
self = .scaleAspectFill
|
||||
case "redraw":
|
||||
self = .redraw
|
||||
case "center":
|
||||
self = .center
|
||||
case "top":
|
||||
self = .top
|
||||
case "bottom":
|
||||
self = .bottom
|
||||
case "left":
|
||||
self = .left
|
||||
case "right":
|
||||
self = .right
|
||||
case "topLeft":
|
||||
self = .topLeft
|
||||
case "topRight":
|
||||
self = .topRight
|
||||
case "bottomLeft":
|
||||
self = .bottomLeft
|
||||
case "bottomRight":
|
||||
self = .bottomRight
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var rawValueString: String {
|
||||
switch self {
|
||||
case .scaleToFill:
|
||||
return "scaleToFill"
|
||||
case .scaleAspectFit:
|
||||
return "scaleAspectFit"
|
||||
case .scaleAspectFill:
|
||||
return "scaleAspectFill"
|
||||
case .redraw:
|
||||
return "redraw"
|
||||
case .center:
|
||||
return "center"
|
||||
case .top:
|
||||
return "top"
|
||||
case .bottom:
|
||||
return "bottom"
|
||||
case .left:
|
||||
return "left"
|
||||
case .right:
|
||||
return "right"
|
||||
case .topLeft:
|
||||
return "topLeft"
|
||||
case .topRight:
|
||||
return "topRight"
|
||||
case .bottomLeft:
|
||||
return "bottomLeft"
|
||||
case .bottomRight:
|
||||
return "bottomRight"
|
||||
@unknown default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension UIView.ContentMode: Codable {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.singleValueContainer()
|
||||
let string = try typeContainer.decode(String.self)
|
||||
guard let mode = UIView.ContentMode(rawValue: string) else {
|
||||
throw ContentModeError.notAContentMode
|
||||
}
|
||||
self = mode
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
try container.encode(rawValueString)
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,10 @@ public class TwoButtonViewModel: MoleculeModelProtocol {
|
||||
case secondaryButton
|
||||
}
|
||||
|
||||
init() { }
|
||||
init(_ primaryButton: ButtonModel?, _ secondaryButton: ButtonModel?) {
|
||||
self.primaryButton = primaryButton
|
||||
self.secondaryButton = secondaryButton
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user