Skip to content

Commit

Permalink
SwiftyViewController added & Example Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
devmehmetates committed Nov 17, 2023
1 parent 699e174 commit bc2dc60
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
31 changes: 16 additions & 15 deletions Sources/SwiftyKit/ExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,40 @@ struct ExampleView_Previews: PreviewProvider {
}

@available(iOS 13.0, *)
final class ExampleView: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Navigation Title"
self.navigationController?.navigationBar.prefersLargeTitles = true
createView()
}

func createView() {
final class ExampleView: SwiftyViewController {
override var content: UIView {
BaseScrollView {
VerticalStack {
for _ in 0...10 {
HorizontalStack {
createCardRow("Row", image: "https://picsum.photos/200")
createCardRow("Row", image: "https://picsum.photos/200")

}.frame(width: 90.0.responsiveW)
.distribution(.equalSpacing)
}
}.padding()
}.embedTo(view)
.fillToSuperView()
}
}

private func createCardRow(_ title: String, image: String) -> UIView {
VerticalStack {
lazy var label = UILabel("History")
.font(.boldSystemFont(ofSize: 15))

return VerticalStack {
UIImageView()
.asyncImage(URL(string: image))
.contentMode(.scaleAspectFill)
.cornerRadius(8)
.clipsToBounds(true)

UILabel("History")
.font(.boldSystemFont(ofSize: 15))
BaseButton(type: .system)
.setTitle("Update Label")
.didClick {
label.text = "Updated"
}

label
}.padding()
.backgroundColor(.systemBackground)
.cornerRadius(10)
Expand Down
41 changes: 41 additions & 0 deletions Sources/SwiftyKit/Kit/Bases/SwiftyViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// SwiftyViewController.swift
//
//
// Created by Mehmet Ateş on 17.11.2023.
//

import UIKit

public protocol SwiftyViewControllerInferface {
var content: UIView { get }
func reDraw()
func cleanDrawed()
func draw()
}

public extension SwiftyViewControllerInferface where Self: UIViewController {
func reDraw() {
cleanDrawed()
draw()
}

func cleanDrawed() {
content.removeFromSuperview()
view.subviews.forEach { $0.removeFromSuperview() }
}

func draw() {
content
.embedTo(view)
.fillToSuperView()
}
}

open class SwiftyViewController: UIViewController, SwiftyViewControllerInferface {
public var content: UIView { view }
open override func viewDidLoad() {
super.viewDidLoad()
draw()
}
}

0 comments on commit bc2dc60

Please sign in to comment.