0

我正在尝试在我的 UITableView 中使用具有 vibrancyEffect 的文本标签创建一个模糊的标题,但是使用这段代码,我得到的只是一个没有任何文本标签的模糊标题......怎么了?:)

- (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];

}

提前致谢!

4

1 回答 1

1

这已经很晚了...但是您将文本设置为清晰的颜色。你期望这会做什么?:)

header.textLabel setTextColor:[UIColor clearColor]];

无论如何,我的建议是尝试这样的事情:

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];
于 2015-03-19T01:44:06.950 回答