AssistoLab / DropDown

A Material Design drop down for iOS
MIT License
2.44k stars 622 forks source link

make textAlignment = .center #235

Open dimabiserov opened 5 years ago

dimabiserov commented 5 years ago

Please add a setting

adrianniebla commented 5 years ago

Why not just create a custom cell and make the optionLabel centered?

OleksiiShulzhenko commented 4 years ago

That would be helpful.

naveedmcs commented 4 years ago
extension DropDown {

    func setData(btn: UIButton?, dataSource: [String]){
        guard let btn = btn else { return }

        self.semanticContentAttribute = .unspecified

        self.anchorView = btn

        self.bottomOffset = CGPoint(x: 0, y: btn.bounds.height)

        self.customCellConfiguration = { (index: Index, item: String, cell: DropDownCell) -> Void in

            cell.optionLabel.textAlignment = .center

        }

        self.dataSource = dataSource

    }

}
 cityDropDown.setData(btn: cityBtn, dataSource: items)
        cityDropDown.selectionAction = {[unowned self](index: Int, item: String) in
            if index == 0 {
                self.selectedCity = nil
                return
            }

            self.cityTextField.text = item
            self.selectedCity = cities[index-1]

        }
Negar-K commented 4 years ago

Add this extension. This would be helpful. extension DropDownCell { override open func awakeFromNib() { super.awakeFromNib() optionLabel.textAlignment = .center } }

nomi1315 commented 2 years ago

yearDropDown.customCellConfiguration = { (index, item, cell) in cell.optionLabel.textAlignment = .center }