GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - sonmbol/UIKitViewBuilder: UIKitViewBuilder: Seamlessly integrate UIView, UITableViewCell, and UICollectionViewCell components into your SwiftUI projects. Elevate your app's UI flexibility with ease!

BranchesTags
Open more actions menu

Latest commit

 

History

14 Commits
14 Commits

Folders and files

NameName
Last commit message
Last commit date
.swiftpm/xcode
.swiftpm/xcode
 
 
Example.xcodeproj
Example.xcodeproj
 
 
Example.xcworkspace
Example.xcworkspace
 
 
Example
Example
 
 
Pods
Pods
 
 
Sources
Sources
 
 
Tests/CellBuilderTests
Tests/CellBuilderTests
 
 
.DS_Store
.DS_Store
 
 
LICENSE
LICENSE
 
 
Package.swift
Package.swift
 
 
Podfile
Podfile
 
 
Podfile.lock
Podfile.lock
 
 
README.md
README.md
 
 
UIKitViewBuilder.podspec
UIKitViewBuilder.podspec
 
 

Repository files navigation

UIKitViewBuilder

UIKitViewBuilder is a versatile Swift framework designed to seamlessly convert any UIView, UITableViewCell, or UICollectionViewCell into a SwiftUI view. This enables configuration and responsiveness to Publisher, making the integration of existing UI components into SwiftUI a breeze. Enhance your development experience with efficiency, excitement, and a touch of magic!

Features

  • Seamless Integration: Effortlessly convert any UIView, UITableViewCell, or UICollectionViewCell to a SwiftUI view.
  • Configurable and Responsive: Fully compatible with SwiftUI and responsive to Publisher.
  • Result Builder: Simplifies the implementation of UIView, UITableViewCell, or UICollectionViewCell as SwiftUI views using UIKitViewBuilder.

Installation

Swift Package Manager

To integrate UIKitViewBuilder into your project using Swift Package Manager, add the following to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/sonmbol/UIKitViewBuilder.git", from: "1.0.0")
]

CocoaPods

To integrate UIKitViewBuilder using CocoaPods, add the following to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '14.0'

target 'YourAppTargetName' do
  use_frameworks!
  pod 'UIKitViewBuilder'
end

Usage

The core idea behind UIKitViewBuilder is to convert any UIView, UITableViewCell, or UICollectionViewCell into a SwiftUI view, making it configurable and responsive to Publisher. Below are some examples to get you started.

Example Usage

Creating a View

struct ContentView: View {
    var body: some View {
        List {
            LabelView.makeView { view in
                view.label.text = "make SwiftUI View"
            }
            LabelView()
                .set(\.label.text, to: "make SwiftUI View")
                .makeView()
            buildEmptyLabelView()
            buildLabelView()
            buildTableViewCell()
            buildCollectionViewCell()
            buildTableViewCells()
            buildCollectionViewCells()
        }
    }
}

class LabelView: UIView {
    lazy var label = addLabel()

    func addLabel() -> UILabel {
        let label = UILabel()
        label.numberOfLines = 0
        label.translatesAutoresizingMaskIntoConstraints = false
        return label
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(label)
        NSLayoutConstraint.activate([
            label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
            label.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16),
            label.topAnchor.constraint(equalTo: topAnchor, constant: 8),
            label.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8)
        ])
    }

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

UIKitViewBuilder for Single Cells

@UIKitViewBuilder
func buildLabelView() -> some View {
    LabelView { view in
        view.label.text = "SwiftUI View UIView"
    }
}

@UIKitViewBuilder
func buildEmptyLabelView() -> some View {
    LabelView()
        .set(\.label.text, to: "Dynamic Content Here")
        .set(\.backgroundColor, to: .red)
}

@UIKitViewBuilder
func buildTableViewCell() -> some View {
    LabelTableViewCell { cell in
        cell.label.text = "SwiftUI View TableViewCell"
    }
}

@UIKitViewBuilder
func buildCollectionViewCell() -> some View {
    LabelCollectionViewCell { cell in
        cell.label.text = "SwiftUI View CollectionViewCell"
    }
}

UIKitViewBuilder for Multiple Cells

@UIKitViewBuilder
func buildLabelViews() -> some View {
    LabelView { cell in
        cell.label.text = "First UIView"
    }
    LabelView { cell in
        cell.label.text = "Second UIView"
    }
    LabelView { cell in
        cell.label.text = "Third UIView"
    }
}

@UIKitViewBuilder
func buildTableViewCells() -> some View {
    LabelTableViewCell { cell in
        cell.label.text = "First TableViewCell"
    }
    LabelTableViewCell { cell in
        cell.label.text = "Second TableViewCell"
    }
    LabelTableViewCell { cell in
        cell.label.text = "Third TableViewCell"
    }
}

@UIKitViewBuilder
func buildCollectionViewCells() -> some View {
    LabelCollectionViewCell { cell in
        cell.label.text = "First CollectionViewCell"
    }
    LabelCollectionViewCell { cell in
        cell.label.text = "Second CollectionViewCell"
    }
    LabelCollectionViewCell { cell in
        cell.label.text = "Third CollectionViewCell"
    }
}

UIKitViewBuilder for Multiple Cells

@UIKitViewBuilder
func buildLabelViews() -> some View {
    LabelView { cell in
        cell.label.text = "First UIView"
    }
    LabelView { cell in
        cell.label.text = "Second UIView"
    }
    LabelView { cell in
        cell.label.text = "Third UIView"
    }
}

@UIKitViewBuilder
func buildTableViewCells() -> some View {
    LabelTableViewCell { cell in
        cell.label.text = "First TableViewCell"
    }
    LabelTableViewCell { cell in
        cell.label.text = "Second TableViewCell"
    }
    LabelTableViewCell { cell in
        cell.label.text = "Third TableViewCell"
    }
}

@UIKitViewBuilder
func buildCollectionViewCells() -> some View {
    LabelCollectionViewCell { cell in
        cell.label.text = "First CollectionViewCell"
    }
    LabelCollectionViewCell { cell in
        cell.label.text = "Second CollectionViewCell"
    }
    LabelCollectionViewCell { cell in
        cell.label.text = "Third CollectionViewCell"
    }
}

How It Works

  • Extraction: The UIView, UITableViewCell, or UICollectionViewCell is first extracted as a UIView.
  • Container: A container is added around it to override intrinsicContentSize since SwiftUI respects the size only, not the constraints.
  • Content Integration: The cell content is added inside the container.
  • Result Builder: To make the view easy to use in SwiftUI, a result builder called UIKitViewBuilder is used.

By following this approach, you can easily integrate your existing UIView, UITableViewCell, or UICollectionViewCell components into SwiftUI, making your development process smoother and more efficient.

About

UIKitViewBuilder: Seamlessly integrate UIView, UITableViewCell, and UICollectionViewCell components into your SwiftUI projects. Elevate your app's UI flexibility with ease!

Topics

frameworkintegrate-uikit-with-swiftuiiosopen-sourceresultbuilderreusable-componentsswiftswiftuiswiftui-uikit-integrationui-componentsuicollectioncell-swiftuiuihostingcontrolleruikituikit-for-swiftuiuitableviewcell-swiftuiuiview-swiftuiuiviewrepresentableuser-interfaceview-builderviewbuilder

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.