Corner radius added to Image and bgImageContainer

This commit is contained in:
Chintakrinda, Arun Kumar (Arun) 2020-08-05 15:45:13 +05:30
parent daf6e7ea01
commit 5d89ae873d
4 changed files with 21 additions and 2 deletions

View File

@ -20,6 +20,7 @@ import Foundation
public var height: CGFloat?
public var contentMode: UIView.ContentMode?
public var localBundle: Bundle?
public var cornerRadius: CGFloat?
public init(image: String, imageFormat: String? = nil, width: CGFloat? = nil, height: CGFloat? = nil) {
self.image = image
@ -38,5 +39,6 @@ import Foundation
case width
case height
case contentMode
case cornerRadius
}
}

View File

@ -247,6 +247,11 @@ import UIKit
if let contentMode = imageModel.contentMode {
imageView.contentMode = contentMode
}
if let cornerRadius = imageModel.cornerRadius {
imageView.clipsToBounds = true
imageView.layer.cornerRadius = cornerRadius
}
}
// MARK: - load functions

View File

@ -19,7 +19,15 @@ open class BGImageMolecule: MoleculeContainer {
}
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
image.setOptional(with: (model as? BGImageMoleculeModel)?.image, delegateObject, additionalData)
super.set(with: model, delegateObject, additionalData)
guard let castModel = model as? BGImageMoleculeModel else {
super.set(with: model, delegateObject, additionalData)
return
}
image.setOptional(with: castModel.image, delegateObject, additionalData)
super.set(with: castModel, delegateObject, additionalData)
if let cornerRadius = castModel.cornerRadius {
layer.cornerRadius = cornerRadius
clipsToBounds = true
}
}
}

View File

@ -13,6 +13,7 @@ open class BGImageMoleculeModel: MoleculeContainerModel {
return "bgImageContainer"
}
public var image: ImageViewModel
public var cornerRadius: CGFloat?
open override func setDefaults() {
if useHorizontalMargins == nil {
@ -31,6 +32,7 @@ open class BGImageMoleculeModel: MoleculeContainerModel {
private enum CodingKeys: String, CodingKey {
case image
case cornerRadius
}
public init(_ image: ImageViewModel, molecule: MoleculeModelProtocol) {
@ -41,6 +43,7 @@ open class BGImageMoleculeModel: MoleculeContainerModel {
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
image = try typeContainer.decode(ImageViewModel.self, forKey:.image)
cornerRadius = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .cornerRadius)
try super.init(from: decoder)
}
@ -48,5 +51,6 @@ open class BGImageMoleculeModel: MoleculeContainerModel {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(image, forKey: .image)
try container.encodeIfPresent(cornerRadius, forKey: .cornerRadius)
}
}