0

I am trying to load xib file for custom keyboard with the following code. After that, I need to unload and then reload again. I don't understand how to reload this code. I would like to know how to do.

- (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;
}
4

1 回答 1

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];
}
于 2013-08-22T22:45:02.507 回答