UITableViewHeaderFooterView transparent

Je suis en train de faire un en-tête personnalisé vue pour cette UITableView et j'aimerais qu'il soit transparent.

Mon code...

Interface...

typedef void(^ActionBlock)();

@interface MyViewHeaderView : UITableViewHeaderFooterView

@property (nonatomic, strong) UIImageView *flagImageView;
@property (nonatomic, strong) UILabel *leagueNameLabel;

@property (nonatomic, copy) ActionBlock tapAction;

@end

Mise en œuvre...

#import "MyViewHeaderView.h"

@interface MyViewHeaderView ()

@end

@implementation MyViewHeaderView

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        //Add customisation here...

        //I have tried everything here...
        self.tintColor = [UIColor colorWithWhite:0.961 alpha:1.0];
        self.alpha = 0.5;

        //self.contentView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
        //self.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
        //can't remember what else.
        //none of it makes it transparent. It sets the colour against
        //a white background. i.e. 50% transparent but with a white opaque background.
        //so I can't see the content of the table scrolling behind it.

        self.flagImageView = [[UIImageView alloc] init];
        self.flagImageView.image = [UIImage imageNamed:@"placeholder_flag"];
        [self.flagImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
        [self.contentView addSubview:self.flagImageView];

        self.leagueNameLabel = [[UILabel alloc] init];
        [self.leagueNameLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
        [self.contentView addSubview:self.leagueNameLabel];

        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped)];
        tapGestureRecognizer.numberOfTapsRequired = 1;
        tapGestureRecognizer.numberOfTouchesRequired = 1;
        [self.contentView addGestureRecognizer:tapGestureRecognizer];

        [self setupConstraints];
    }
    return self;
}

- (void)setupConstraints
{
    //adding constraints...
}

- (void)viewTapped
{
    self.tapAction();
}

@end

Dans mon UITableViewDelegate je suis de chargement l'en-tête comme...

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    MyViewHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"HeaderView"];

    League *league = self.leagues[(NSUInteger) section];

    headerView.leagueNameLabel.text = league.name;
    headerView.tapAction = ^(){
        [self leagueTapped:league];
    };

    return headerView;
}

Cela fonctionne bien, l'en-tête est de montrer correctement. Juste sans transparence.

J'aimerais avoir une vue d'en-tête comme la norme de vue où vous pouvez voir la vue de la table de contenu défiler derrière elle.

S'il vous plaît pouvez-vous me faire savoir comment faire cela.

source d'informationauteur Fogmeister