我正在尝试使用以下代码加载自定义键盘的xib文件。之后,我需要卸载然后重新加载。我不明白如何重新加载此代码。我想知道怎么做。
- (id)init {
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
CGRect frame;
if(UIDeviceOrientationIsLandscape(orientation))
frame = CGRectMake(0, 0, 480, 162);
else
frame = CGRectMake(0, 0, 320, 216);
self = [super initWithFrame:frame];
if (self)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PMCustomKeyboard" owner:self options:nil];
[[nib objectAtIndex:0] setFrame:frame];
self = [nib objectAtIndex:0];
[[NSBundle mainBundle] loadNibNamed:@"KeyBoardAccView_iPhone" owner:self options:nil];
}
[self.altButton setTitle:kAltLabel forState:UIControlStateNormal];
[self.returnButton setTitle:kReturnLabel forState:UIControlStateNormal];
self.returnButton.titleLabel.adjustsFontSizeToFitWidth = YES;
[self loadCharactersWithArray:kChar];
[self.spaceButton setBackgroundImage:[PMCustomKeyboard imageFromColor:[UIColor colorWithWhite:0.5 alpha:0.5]]
forState:UIControlStateHighlighted];
self.spaceButton.layer.cornerRadius = 7.0;
self.spaceButton.layer.masksToBounds = YES;
self.spaceButton.layer.borderWidth = 0;
[self.spaceButton setTitle:kSpaceLabel forState:UIControlStateNormal];
return self;
}
-(void)setTextView:(id<UITextInput>)textView {
if ([textView isKindOfClass:[UITextView class]])
[(UITextView *)textView setInputView:self];
else if ([textView isKindOfClass:[UITextField class]])
[(UITextField *)textView setInputView:self];
_textView = textView;
NSLog(@"setTextView");
}
-(id<UITextInput>)textView {
return _textView;
}
答案 0 :(得分:2)
我刚发布了一个关于如何从.xib文件加载自定义UIView的示例项目。
https://github.com/PaulSolt/CompositeXib
你需要一个额外的UIView插座,这个代码用于名为WidgetView的类/ .xib文件:
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if(self) {
[self setup];
}
return self;
}
- (void)setup {
[[NSBundle mainBundle] loadNibNamed:@"WidgetView" owner:self options:nil];
[self addSubview:self.view];
}