我正试图在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];
}
提前感谢!
太晚了。。。但是您将文本设置为清晰的颜色。你期望它做什么?:)
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];