AssistoLab / DropDown

A Material Design drop down for iOS
MIT License
2.43k stars 623 forks source link

Add separatorInset for customization #326

Open thingineeer opened 10 months ago

thingineeer commented 10 months ago

🪫 [Before change]

When implementing a custom drop-down menu, a separator is often needed.

dropDown.separatorColor's default color is .clear right?

But if you use dropDown.separatorColor = .black here, it looks like this

drop1

Usually, there may be people who want to fill the left side.

What if you add my code? tableView.separatorInset.left = 0


🪫 [After change]

drop2

good


⭐️ But do you see the Separator in the bottom cell? It's really a little uncomfortable

image


That's okay~

We have customCellConfiguration~

Just create a CGRect with the same color as dropDown in customCellConfiguration and add it to the bottom of dropDown.

Like this

dropDown.customCellConfiguration = { (index: Index, item: String, cell: DropDownCell) -> Void in
            let lastDivideLineRemove = UIView(frame: CGRect(origin: CGPoint(x: 0, y: 119), size: CGSize(width: 170, height: 10)))
            lastDivideLineRemove.backgroundColor = .white // ⭐️ Same as the background color of dropDown
            cell.addSubview(lastDivideLineRemove)
        }

🍎 Result

drop3

🤔 Review

dropDown.customCellConfiguration = { (index, item, cell) in
      cell.separatorInset = .zero
      cell.layoutMargins = .zero
}

You can add it like this, but I think it's better to just add tableView.separatorInset.left = 0 😄