Monday, February 26, 2024
HomeiOS Developmentios - Learn how to set appropriate tintColor with chosen however not...

ios – Learn how to set appropriate tintColor with chosen however not centered UICellAccessory.customView


In a UICollectionView inside a UISplitViewController format, I’ve a UICollectionView.CellRegistration that reveals below sure situations a warning badge as UICellAccessory.

This warning badge accent is predicated on the next code:

func warningBadge(cell: UICollectionViewListCell) -> UICellAccessory  {

    return UICellAccessory.customView(configuration: 
    .init(customView: UIImageView(picture: UIImage(systemName: "exclamationmark.triangle")), 
           placement: .trailing(),
 reservedLayoutWidth: .customized(18), 
           tintColor: UIColor(dynamicProvider: { assortment in

        if cell.isSelected {
            return .lightText
        }
        else {
            return .systemRed
        }
    })))
}

This works nice, besides when the main focus within the app strikes to a different half within the Cut up View management.

In that case the chosen cell present a light-weight gray background, as an alternative of a tintColor background (which is appropriate), however the warning badge nonetheless has a particular look, which makes it arduous to see (lightText on prime of sunshine gray background).

In case when the cell is chosen however not centered, the picture ought to have the non chosen tintColor (.systemRed on this instance code).

I attempted to make use of cell.isFocused as an alternative of, or along with cell.isSelected, however this does not work.

Curiously, cell.isFocused does work appropriately for UICellAccessory.label equipment, however apparently not for a UICellAccessory.customView with a picture management.

Learn how to give a customized accent the right tintColor when the cell is chosen, however not centered?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments