You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Help needed] Problems in changing underlying TableViewCell label #12
Thanks for the feedback. The label is contained in the associated UITableViewCell, instead of OptionRow itself. To fix the compiler error, it should be:
// When it's OptionRow<CustomOptionCell>
letoptionRowLabelAppearance=UILabel.appearance(whenContainedInInstancesOf:[CustomOptionCell.self])optionRowLabelAppearance.textColor=Theme.textColor
UIAppearance issue
I find that UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self]) works alright when the cell is dequeued with an identifier set in the storyboard.
But somehow it doesn't work when the cell is either registered with a class:
Since QuickTableViewController initializes table view cells in code without using a storyboard, the labels in cells don't pick up the appearance settings. One way to work around this issue might be registering a nib object.
Workaround with a nib object
Add a CustomOptionCell.xib:
drag in a Table View Cell object to replace the default view
set its Style to Basic or Subtitle
set the Custom Class to CustomOptionCell
set the reuse identifier to CustomOptionCell, same as the type name
thanks for your quick answer. So much appreciated!
Then the table view will dequeue the cell registered in the nib and the UIAppearance customization should work in those cells.
Hope this helps.
This indeed helped and I could successfully change the label color 👍
Unfortunately, the problem remains with SwitchCell and TapActionCell - got stuck creating a xib file directly using TapActionCell eg.
There should be an easier way to get the labels styled (maybe using
Activity
bcylin commentedon Jan 22, 2018
Hi Karsten,
Thanks for the feedback. The label is contained in the associated
UITableViewCell, instead ofOptionRowitself. To fix the compiler error, it should be:UIAppearance issue
I find that
UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self])works alright when the cell is dequeued with an identifier set in the storyboard.But somehow it doesn't work when the cell is either registered with a class:
or initialized in code:
Since
QuickTableViewControllerinitializes table view cells in code without using a storyboard, the labels in cells don't pick up the appearance settings. One way to work around this issue might be registering a nib object.Workaround with a nib object
Add a
CustomOptionCell.xib:CustomOptionCellCustomOptionCell, same as the type nameRegister the nib to the table view with:
Instead of using the default
OptionRowin the section, specify the associated cell typeOptionRow<CustomOptionCell>.Then the table view will dequeue the cell registered in the nib and the
UIAppearancecustomization should work in those cells. Hope this helps.karstengresch commentedon Jan 22, 2018
Hi Ben,
thanks for your quick answer. So much appreciated!
Unfortunately, the problem remains with SwitchCell and TapActionCell - got stuck creating a xib file directly using TapActionCell eg.
There should be an easier way to get the labels styled (maybe using
? But I'm not really sure, how.
Any idea at your side?
Best wishes,
Karsten
bcylin commentedon Jan 23, 2018
Hi Karsten,
I tried it on the Example app.
https://github.com/bcylin/QuickTableViewController/compare/feature/ui-appearance
Although
TapActionCellsets its text color during initialization, it seems no problem with the UIAppearancetextColoron iOS 11.2 simulator.