Подклассы UILabel

Я читал на этом же сайте, как вставить и UILabel (подкласс UILabel и переопределить требуемые методы). Прежде чем добавить его в свое приложение, я решил протестировать его в отдельном тестовом приложении. Код показан ниже.

Вот MyUILabel.h

#import <UIKit/UIKit.h>

@interface MyUILabel : UILabel

@end

Вот MyUILabel.m

#import "MyUILabel.h"
#import <QuartzCore/QuartzCore.h>

@implementation MyUILabel

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

// for border and rounding
-(void) drawRect:(CGRect)rect
{
    self.layer.cornerRadius = 4.0;
    self.layer.borderWidth = 2;

    [super drawRect:rect];
}

// for inset
-(void) drawTextInRect:(CGRect)rect
{
    UIEdgeInsets insets = {0, 5, 0, 5};

    [super drawTextInRect: UIEdgeInsetsInsetRect(rect, insets)];
}

Вот мой ViewController.h

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


@interface ViewController : UIViewController
{
    MyUILabel   *myDisplay;
}

@property (strong, nonatomic) IBOutlet MyUILabel *myDisplay;

@end

Вот ViewController.m:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize myDisplay;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    myDisplay.text = @"Hello World!";
}

- (void)viewDidUnload
{
    [self setMyDisplay:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

Ни один из методов в MyUILabel.m (который я переопределяю) не вызывается.

Мы очень ценим понимание того, почему.

С уважением,

Рамон.

6
задан Phantom59 4 April 2012 в 03:16
поделиться