Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove background color on UITableViewAccessory

I added Chameleon to a project and it works well, for the most part. One issue I've stumbled into when setting a theme for a project is a background being placed on UITableViewCell accessories.

Here's what my accessory looks like with the ChameleonFramework theme enabled:

enter image description here

My desired accessory color is blue with no background. Chameleon seems to invert these.

I also opened up Debug View Hierarchy to see what's going on. I can "see" the problem, but I can't figure out how to get at the accessory view's background to change it back to UIColor.white, nor can I figure out how to change the checkmark to UIColor.blue

enter image description here

I've tried to tinker with the tint of the accessory with the following command in cellForRowAtIndexPath:

cell.tintColor = UIColor.blue

I also tried changing the background of the accessoryView:

cell.accessoryView!.tintColor = UIColor.blue
cell.accessoryView?.backgroundColor = UIColor.white

I also tried changing the tint of the tableView:

tableView.tintColor = UIColor.blue

Any other ideas how I'd go about changing this are greatly appreciated.

like image 556
Adrian Avatar asked Apr 20 '26 15:04

Adrian


2 Answers

Apparently, this is a bug with Chameleon that is presently being worked on.

Digging around in Debug View Hierarchy, I saw that the checkmark was drawn as a UIButton. Rather than changing it on the MyViewController, I opted to change the UIButton class appearance in AppDelegate when it's contained in a UITableViewCell.

I was able to resolve my problem by calling the following commands from AppDelegate:

    UIButton.appearance(whenContainedInInstancesOf: [UITableViewCell.classForCoder() as! UIAppearanceContainer.Type]).backgroundColor = UIColor.clear
    UIButton.appearance(whenContainedInInstancesOf: [UITableViewCell.classForCoder() as! UIAppearanceContainer.Type]).tintColor = FlatBlue()
like image 148
Adrian Avatar answered Apr 22 '26 07:04

Adrian


When using Chameleon-RCI 2.1.0.2 with Xamarin I had the same problem when using UITableViewCellAccessory.DetailDisclosureButton.

UITableViewCell cell = tableView.DequeueReusableCell("A");
if (cell == null)
{
        cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "A");
        cell.Accessory = UITableViewCellAccessory.DetailDisclosureButton;
}

Similar to Adrian's answer but with C# the fix was the following in the AppDelegate class.

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
    // Override point for customization after application launch.
    // If not required for your application you can safely delete this method

    UIColor secondaryColor = ChameleonColor.FlatWatermelon;
    Chameleon.SetGlobalTheme(ChameleonColor.FlatMint, secondaryColor, ContentStyle.Contrast);

    UIButton.UIButtonAppearance buttonAppearance = UIButton.AppearanceWhenContainedIn(new Type[] { typeof(UITableViewCell) });
    buttonAppearance.BackgroundColor = UIColor.Clear;
    buttonAppearance.TintColor = secondaryColor;

    return (true);
}
like image 25
Roj Avatar answered Apr 22 '26 05:04

Roj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!