Swiftpack.co - Package - sahibhussain/SahibHelper

SahibHelper

Features

  • FontAwesome support
  • view shadow
  • toast show and with completion
  • network helper
  • much more

!Important

add font awesome ttf file to your project also mark them in your info.plist

Installation

dependencies: [
.package(url: "https://github.com/sahibhussain/SahibHelper.git", .upToNextMinor(from: "1.3.0"))
]

💡 ** Tip:** use the latest release version written on the badge.

Main Classes

let designHelper = DesignHelper.shared
let networkHelper = NetworkHelper.shared

Custom Switch as SahibSwitch which inherits UIView

Available Alignment Options

You can use any combination of horizontal and vertical alignment to achieve your desired layout.

Horizontal Alignment:

  • horizontalAlignment = .left

Example layout for horizontalAlignment = .left

  • horizontalAlignment = .right

Example layout for horizontalAlignment = .right

  • horizontalAlignment = .justified

Example layout for horizontalAlignment = .justified

Vertical Alignment:

  • verticalAlignment = .top

Example layout for verticalAlignment = .top

  • verticalAlignment = .center

Example layout for verticalAlignment = .center

  • verticalAlignment = .bottom

Example layout for verticalAlignment = .bottom

Usage

Setup in Interface Builder

  1. You have a collection view in Interface Builder and setup its data source appropriately. Run the app and make sure everything works as expected (except the cell alignment).

  2. In the Document Outline, select the collection view layout object.

    Screenshot of the Flow Layout object in Interface Builder

  3. In the Identity Inspector, set the layout object's custom class to AlignedCollectionViewFlowLayout.

    Screenshot: How to set a custom class for the layout object in Interface Builder

  4. Add and customize the following code to your view controller's viewDidLoad() method:

    let alignedFlowLayout = collectionView?.collectionViewLayout as? AlignedCollectionViewFlowLayout
    alignedFlowLayout?.horizontalAlignment = .left
    alignedFlowLayout?.verticalAlignment = .top
    

    If you omit any of the last two lines the default alignment will be used (horizontally justified, vertically centered).

    💡 Pro Tip: Instead of type-casting the layout as shown above you can also drag an outlet from the collection view layout object to your view controller.

Setup in code

  1. Create a new AlignedCollectionViewFlowLayout object and specify the alignment you want:

    let alignedFlowLayout = AlignedCollectionViewFlowLayout(horizontalAlignment: .left, verticalAlignment: .top)
    
  2. Either create a new collection view object and and initialize it with alignedFlowLayout:

    let collectionView = UICollectionView(frame: bounds, collectionViewLayout: alignedFlowLayout)
    

    or assign alignedFlowLayout to the collectionViewLayout property of an existing collection view:

    yourExistingCollectionView.collectionViewLayout = alignedFlowLayout
    
  3. Implement your collection view's data source.

  4. Run the app.


Additional configuration

For the left and right alignment AlignedCollectionViewFlowLayout distributes the cells horizontally with a constant spacing which is the same for all rows. You can control the spacing with the minimumInteritemSpacing property.

alignedFlowLayout.minimumInteritemSpacing = 10

Despite its name (which originates from its superclass UICollectionViewFlowLayout) this property doesn't describe a minimum spacing but the exact spacing between the cells.

The vertical spacing between the lines works exactly as in UICollectionViewFlowLayout:

alignedFlowLayout.minimumLineSpacing = 10

Github

link
Stars: 0

Used By

Total: 0

Releases

Added Headers - 2020-06-05 09:25:49

Added Header Support in API Requests

Added CollectionViewLayout Allignment - 2020-04-16 09:24:32

Now you can Align you cell to left, right, top, bottom instead of the collectionView default behaviour

Error Resolved - 2020-04-13 09:15:59

resolved error while importing package

Initial Release - 2020-04-13 07:47:17

this is an initial release with all the neccessary update