【发布时间】:2014-07-17 06:59:40
【问题描述】:
我正在创建一个简单的代码,它允许我在 UISwitcher 之外实例化一个 UILabel。 切换器正在正常创建,我创建了一个“UIRadio”类以在开始时正确实例化标签。
这是.m:
#import "UIRadio.h"
@implementation UIRadio
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(id)initWithLabel:(CGRect)frame Label:(NSString*)labelText
{
self = [super init];
if (self) {
self.frame=frame;
label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 100)];
label.text=labelText;
[self.superview addSubview:label];
}
return self;
}
-(void)removeFromSuperview{
[label removeFromSuperview];
}
@end
这是.h:
#import <UIKit/UIKit.h>
@interface UIRadio : UISwitch{
UILabel *label;
}
- (id)initWithLabel:(CGRect)frame Label:(NSString*)label;
@end
UILabel 似乎已正确创建,但未显示在视图中。 有什么线索吗?
谢谢
【问题讨论】:
标签: ios xcode uilabel uiswitch