GithubHelp home page GithubHelp logo

dlamptey / wrappinghstack Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dkk/wrappinghstack

0.0 0.0 0.0 132 KB

A SwiftUI HStack with the ability to wrap contained elements

License: MIT License

Swift 100.00%

wrappinghstack's Introduction

WrappingHStack

WrappingHStack is a UI Element that works in a very similar way to HStack, but automatically positioning overflowing elements on next lines.

Example

Example

WrappingHStack {
    Text("WrappingHStack")
        .padding()
        .font(.title)
        .border(Color.black)
    
    Text("can handle different element types")
    
    Image(systemName: "scribble")
        .font(.title)
        .frame(width: 200, height: 20)
        .background(Color.purple)
    
    Text("and loop")
        .bold()
    
    WrappingHStack(data: 1...20, id:\.self) {
        Text("Item: \($0)")
            .padding(3)
            .background(Rectangle().stroke())
    }.frame(minWidth: 250)
}
.padding()
.border(Color.black)

Installation

Requirements iOS 13+

Swift Package Manager

  1. In Xcode, open your project and navigate to File โ†’ Swift Packages โ†’ Add Package Dependency.
  2. Paste the repository URL (https://github.com/dkk/WrappingHStack) and click Next.
  3. For Rules, select version.
  4. Click Finish.

Swift Package

.package(url: "https://github.com/dkk/WrappingHStack", .upToNextMajor(from: "1.1.0"))

Usage

Import the WrappingHStack package to your view:

import WrappingHStack

use it like you would use HStack for single elements:

WrappingHStack {
    /* some views */
    NewLine() // Optional: Use NewLine to force the next element to be placed in a next line
    /* some more views */
}

or like a ForEach to loop over items:

WrappingHStack(data: 1...30, id:\.self) {
    Text("Item: \($0)")
}

Known bugs

  • Sometimes, line breaks caused by NewLine() are not shown in the preview canvas (they do work in the live preview).

Support

If you want to support this project, you can buy me a ๐Ÿช

License

WrappingHStack is released under the MIT License.

wrappinghstack's People

Contributors

dkk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.