Пользовательский UILabel не показывает текст

Я сделал пользовательский класс UILabel, в котором я провожу красную линию у основания кадра. Красная строка показывает, но я не могу заставить текст показывать.

#import <UIKit/UIKit.h>


@interface LetterLabel : UILabel {

}

@end    


#import "LetterLabel.h"


@implementation LetterLabel


- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    return self;
}


- (void)drawRect:(CGRect)rect {
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0.0, self.frame.size.height);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), self.frame.size.width, self.frame.size.height);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
}


- (void)dealloc {
    [super dealloc];
}


@end

#import <UIKit/UIKit.h>
#import "Word.h"

@interface WordView : UIView {
    Word *gameWord;
}

@property (nonatomic, retain) Word *gameWord;

@end

@implementation WordView

@synthesize gameWord;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];

        LetterLabel *label = [[LetterLabel alloc] initWithFrame:CGRectMake(0, 0, 20, 30)];
        label.backgroundColor = [UIColor cyanColor];
        label.textAlignment = UITextAlignmentCenter;
        label.textColor = [UIColor blackColor];
        [label setText:@"t"];
        [self addSubview:label]; 
    }
    return self;
}


- (void)drawRect:(CGRect)rect {
    // Drawing code
}


- (void)dealloc {
    [gameWord release];
    [super dealloc];
}


@end
7
задан Oscar 7 March 2010 в 12:43
поделиться

1 ответ

Конечно, ваша LetterLabel должна в какой-то момент вызвать drawRect: от UILabel?

-(void)drawRect:(CGRect)rect {
   // Your stuff goes here
   [super drawRect: rect];
}
22
ответ дан 6 December 2019 в 08:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: