この同じサイトで、挿入および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 のメソッド (Im がオーバーライドしている) は呼び出されません。
その理由についての洞察は大歓迎です。
よろしく、
ラモン。