intuit / CardParts

A reactive, card-based UI framework built on UIKit for iOS developers.
Other
2.52k stars 225 forks source link

Top margins solutions for large title navigationBar #163

Closed vietnguyen09 closed 5 years ago

vietnguyen09 commented 5 years ago

Hi guys,

Could anyone help me to add an extra space on top of the CardParts? Here is what I dealing with now.

image

I use CardPartSpacerView but is not working.

Any way to fix this?

badrinathvm commented 5 years ago

You need to add space on top of Another Card text card ?

vietnguyen09 commented 5 years ago

I need this whole card section has space between my large title navigation bar header, you can see them stick together.

badrinathvm commented 5 years ago

this view would be embedded inside the collection view. Get the flow layout of it and set section inset space.

let layout = self.collectionview.collectionviewFlowlayout as? UIcollectionViewflowlayout layout.sectionInset = UIEdgeInset(top:10, left:10, bottom:10, right :10)

vietnguyen09 commented 5 years ago

No this is not collectionview, here is my temporary solution.

Firstly, I create a Swift file called SpacerCardParts.swift which are use TransparentCardTrait and NoTopBottomMarginsCardTrait

import Foundation
import CardParts

class SpacerCardParts: CardPartsViewController, TransparentCardTrait, NoTopBottomMarginsCardTrait {

}

Then in my ViewController.swift I added this SpacerCardParts

let cards: [CardPartsViewController] = [
    SpacerCardParts(),
    DateSelectController()
]
loadCards(cards: cards)

If there is any better way please let me know.

Thanks

badrinathvm commented 5 years ago

Try below code in SpaceCardParts

class SpacerCardParts: CardPartsViewController, TransparentCardTrait, NoTopBottomMarginsCardTrait {
    override func viewDidLoad() {
             super.viewDidLoad()
            let spacerView =CardPartSpacerView(height:20)
            spacerView.margins = UIEdgeInsets(top:10, left:0, bottom:10, right:0)
            setupCardParts(spacerView)
      }
}
badrinathvm commented 5 years ago

or alternatively u can add below code inside viewDidLoad() of ViewController.swift, assuming

class ViewController:CardsViewController {
     override func viewLoad() {
         let layout = self.collectionview.collectionViewFlowLayout as? UICollectionViewfFlowLayout
         layout.sectionInset = UIEdgeInset(top:10, left:10, bottom:10, right :10)
     }
}

as CardsViewController embeds CollectionView.

vietnguyen09 commented 5 years ago

Unfortunately, it does not work somehow.

image

badrinathvm commented 5 years ago

Correct the spelling of uicollectionviewflowlayout

vietnguyen09 commented 5 years ago

Thanks, correct syntax for Swift 4 - 5 is

let layout = self.collectionView.collectionViewLayout as? UICollectionViewFlowLayout
layout!.sectionInset = UIEdgeInsets(top:100, left:10, bottom:10, right :10)

It works like a charm, thanks @badrinathvm

badrinathvm commented 5 years ago

You welcome. Closing the issue as it’s working as expected.