Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Snapshot doesn't render UIApperances setups #91

Closed
thibault-carpentier opened this issue Jun 17, 2015 · 9 comments
Closed

Snapshot doesn't render UIApperances setups #91

thibault-carpentier opened this issue Jun 17, 2015 · 9 comments
Labels

Comments

@thibault-carpentier
Copy link

The snapshot render the UI without rendering view with the setup of their UIApperances selector.

This may help

According to the 2011 WWDC video introducing UIAppearance, the customizations are applied right before -layoutSubviews is called on the view.

@nscoding
Copy link
Contributor

Thank you @loadex for opening this.

The layoutSubviews method is called correctly but it seems that the view needs to be added on a UIWindow for the appearance proxy to apply the style.

I will need to spend some time to figure out a good solution but for now something like this will work:

  [[UISwitch appearance] setOnTintColor:[UIColor blueColor]];
  [[UISwitch appearance] setThumbTintColor:[UIColor lightGrayColor]];
  UISwitch *control = [[UISwitch alloc] init];
  control.on = YES;

  UIWindow *window = [[UIWindow alloc] initWithFrame:control.bounds];
  [window addSubview:control];
  FBSnapshotVerifyView(control, @"");

@nscoding nscoding added the bug label Jun 17, 2015
@thibault-carpentier
Copy link
Author

@nscoding Thanks for this solution ! I will use it while waiting for your update. Your solution doesn't seem to work when appearances are used with appearanceWhenContainedIn. Any idea why or how to make this work ?

@nscoding
Copy link
Contributor

@loadex I will check it and get back to you.

@nscoding
Copy link
Contributor

@loadex can you give me an example how you use appearanceWhenContainedIn and how your test looks?

@thibault-carpentier
Copy link
Author

Thanks for your reply @nscoding
Here is my produced screenshot :
testviewlayout 2x

My view hierarchy look like :
UINavigationController-> HelpViewController -> HelpView -> UITableView -> LeftMenuCell (containing one UIImageView and on UILabel)

My apperances setups are :

 [UIImageView appearance].tintColor = [HHTheme pinkColor];
  [UIImageView appearanceWhenContainedIn:[LeftMenuTableViewCell class], [HelpViewController class], nil].tintColor = [HHTheme blueBlack];
    [UILabel appearanceWhenContainedIn:[LeftMenuTableViewCell class], [HelpViewController class], nil].tintColor = [HHTheme blueBlack];
[UIView appearance].tintColor = [HHTheme pinkColor];

My test file :

@interface HelpViewControllerTests : FBSnapshotTestCase
@property (nonatomic, strong, readwrite) UINavigationController *nav;
@property (nonatomic, strong, readwrite) HelpViewController *vc;
@end

@implementation HelpViewControllerTests

- (void)setUp {
    [super setUp];
//    self.recordMode = YES;

    HelpViewController *vc = [[HelpViewController alloc] init];
    self.nav = [[UINavigationController alloc] initWithRootViewController:vc];
    self.vc = (HelpViewController*)self.nav.topViewController;
    self.vc.versionVM = [[AppVersionViewModel alloc] init];
    self.vc.dataSource = [[HelpViewControllerTableViewDataSource alloc] init];
    UIWindow *window = [[UIWindow alloc] initWithFrame:self.nav.view.bounds];
    [window addSubview:self.nav.view];
}

- (void)tearDown {
    [super tearDown];
    self.vc = nil;
    self.nav = nil;
}

- (void)testViewLayout {
    FBSnapshotVerifyView(self.nav.view, @"");
}

As you can see, the UIImageView adopt the pink color instead of the blueblack and the label is not blueblack either. Are my tests correct ?

@nscoding
Copy link
Contributor

Thank for your detailed message.

  • If I am not mistaken UILabel doesn't have tintColor property (maybe you meant textColor), can you try that?
  • What is the purpose of [UIView appearance].tintColor = [HHTheme pinkColor]; ? maybe backgroundColor ?
  • Could you also try [window setRootViewController:self.vc] ?

@thibault-carpentier
Copy link
Author

@nscoding Thanks for you answer :

If I am not mistaken UILabel doesn't have tintColor property (maybe you meant textColor), can you try that?

The tintColor property works fine for the textcolor when i'm using the app. This change well the textColor. The TextColor property is not referenced to be compatible with the uiappearance proxy. I used this link to check the headers, and learn more about this. That's why I tried the tint color and it work fine this way.

What is the purpose of [UIView appearance].tintColor = [HHTheme pinkColor]; ? maybe backgroundColor ?

Same here, the tintColor allow me to change so textColor on controls, I've set it as my default value everywhere else, what's weird is that it is not working on my labels here.

Could you also try [window setRootViewController:self.vc] ?

Can't explain the new results here :
testviewlayout 2x
Seem that the nav bar is now no longer transparent (as you can see i had a cell hidden behind it on the previous screenshot) The nav bar is styled properly. But nothing changed on the labels in my cell view. The images have the good colors though.

I hope this help !

Edit : I've just checked again my labels, turn out you can't set the textcolor using uiapperances, so your temporary fix is now working correctly ! Sorry for misleading you ! 😉

@nscoding
Copy link
Contributor

@loadex thanks for the update, I don't have a better solution for now other than the on above. I'll keep the issue open.

@nscoding
Copy link
Contributor

#100 is addressing this issue, I will now close the issue but please reopen if you think otherwise.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants