Linda Keating
Linda Keating

Reputation: 2435

Why is this UILabel not showing in SKScene?

I'm trying to add a UILabel to a SpriteKitView but it won't show up.

I've set up the UILabel as a property of the SKview in .h file like this:

@interface LnbScene : SKScene

@property (nonatomic, retain) UILabel *teidealTitle;

@end

Then in the implementation file I have tried to initialize the label in both the initWithSize method and the didMoveToView method with the following code: (neither works )

-(id) initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
    NSLog(@"LnbScene");
    self.backgroundColor = [SKColor colorWithRed:38.0f/255.0f green:42.0f/255.0f blue:46.0f/255.0f alpha:1];

    CGRect labelFrame = CGRectMake(120, 300, 500, 100);
    _teidealTitle= [[UILabel alloc] initWithFrame:labelFrame];


    NSString *labelText = @"LÍON NA BEARNAÍ";
    [_teidealTitle setText:labelText];
    [_teidealTitle setTextColor:[UIColor whiteColor]];
    [_teidealTitle setFont:[UIFont fontWithName:NULL size:23]];
    [_teidealTitle setTextAlignment:NSTextAlignmentCenter];
    [_teidealTitle setNumberOfLines:0];

}
return self;

}

I did also try looking at SKLabelNode instead but didn't have any luck with that either.

Any pointers most welcome.

Upvotes: 0

Views: 552

Answers (1)

Altimir Antonov
Altimir Antonov

Reputation: 5056

Just use somewhere

[self.view addSubview: _teidealTitle];

With this code you will put the label in the specific view.

Upvotes: 1

Related Questions