Skip to content

Instantly share code, notes, and snippets.

@andru255
Last active September 1, 2018 18:43
Show Gist options
  • Save andru255/ed1d4315812cc426d82c7d9210030780 to your computer and use it in GitHub Desktop.
Save andru255/ed1d4315812cc426d82c7d9210030780 to your computer and use it in GitHub Desktop.
disable shadow and ink effect on material chip component
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "locationChip", for: indexPath) as? MDCChipCollectionViewCell else {
return MDCChipCollectionViewCell()
}
let item = handler?.getRegisteredItems()[indexPath.row]
cell.chipView.titleLabel.text = item?.display
cell.alwaysAnimateResize = false
// Estableciendo la fuente personalizada
cell.chipView.titleFont = UIFont(name: "gothambook", size: 14)
// Estableciendo el color y ancho del borde
let borderColor = UIColor(named: Global.Colors.mainGreenUrb)
cell.chipView.setBorderWidth(1, for: .normal)
cell.chipView.setBorderColor(borderColor, for: .normal)
// Estableciendo el background según su estado
cell.chipView.setInkColor(UIColor.clear, for: .normal)
cell.chipView.setBackgroundColor(UIColor.white, for: .normal)
cell.chipView.setBackgroundColor(cell.chipView.backgroundColor(for: .normal), for: .selected)
cell.chipView.setShadowColor(UIColor.clear, for: .normal)
// Agregando el botón de eliminar
let closeButton = closeBtn()
closeButton.tag = indexPath.row
closeButton.addTarget(self, action: #selector(onRemove), for: .touchUpInside)
cell.chipView.accessoryView = closeButton
cell.chipView.accessoryPadding.right = 3
cell.sizeToFit()
return cell
func closeBtn () -> UIButton {
let image = #imageLiteral(resourceName: "ChipCloseIcon")
image.withRenderingMode(.alwaysTemplate)
let button = UIButton(frame: .zero)
button.tintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 0.7)
button.setImage(image, for: .normal)
return button
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment