Tibbe
Tibbe

Reputation: 417

Unable to use UIVibrancyEffect with tableView header text label

I'm trying to crate a blurry header in my UITableView with a text label that has the vibrancyEffect, but with this code all I get is a blurry header without any text labels... What's wrong? :)

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    // Header Background color
    view.tintColor = [UIColor clearColor];

    // header Text Color
    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
    [header.textLabel setTextColor:[UIColor clearColor]];

    //Header blur
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *visualEffectView;
    visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    visualEffectView.frame = header.bounds;
    [header addSubview:visualEffectView];

    // Text vibrancyEffect
    UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];
    UIVisualEffectView *vibrancyEffectView = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];
    vibrancyEffectView.frame=header.textLabel.frame;
    [vibrancyEffectView.contentView addSubview:header.textLabel];
    [visualEffectView.contentView addSubview:vibrancyEffectView];

}

Thanks in advance!

Upvotes: 0

Views: 709

Answers (1)

Mark Zgaljic
Mark Zgaljic

Reputation: 11

This is late...but you set the text to a clear color. What did you expect this to do? :)

header.textLabel setTextColor:[UIColor clearColor]];

Anyway my suggestion would be to try something like this:

UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
[header.textLabel setTextColor:[UIColor whiteColor]];
header.textLabel.backgroundColor = [UIColor clearColor];

//making background clear, and then placing a blur view across the entire header (execpt the uilabel)
UIVisualEffectView *blurEffectView;
view.tintColor = [UIColor clearColor];
blurEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
blurEffectView.frame = view.bounds;
blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[view addSubview:blurEffectView];

[view bringSubviewToFront:header.textLabel];
[view sendSubviewToBack:blurEffectView];

Upvotes: 1

Related Questions