2012-05-26 15 views
0

我想用我自己的键盘类与文本字段。我怎样才能简单而正确地使用它?如何正确使用自己的键盘与uitextfields

现在我已经得到的东西是这样的:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
UITouch *touch = [[event allTouches] anyObject]; 
CGPoint location = [touch locationInView:overlay]; 


CGRect lRect = CGRectMake(location.x, location.y, 1, 1); 
if (CGRectIntersectsRect(lRect, self.tc.frame)) { 
    textFieldID = self.tc.tag; 
} 

if (CGRectIntersectsRect(lRect, self.tm.frame)) { 
    textFieldID = self.tm.tag; 
} 

if (CGRectIntersectsRect(lRect, self.tp.frame)) { 
    textFieldID = self.tp.tag; 
} 
string = [NSMutableString stringWithString:@"0"]; 
} 

但我的文本框是上述文本框的禁用和UIView的地方检测选择了哪个文本框。

-(UITextField *)initializeTextFieldWithFrame:(CGRect)frame andTag:(Byte)tag { 
UITextField *tf = [[UITextField alloc] initWithFrame:frame]; 
[tf setBackgroundColor:[UIColor colorWithRed:52.0/255.0 green:114.0/255.0 blue:151.0/255.0 alpha:1.0]]; 
[tf setTextColor:[UIColor whiteColor]]; 
[tf setFont:[UIFont fontWithName:@"Helvetica" size:18.0]]; 
[tf setTextAlignment:UITextAlignmentCenter]; 
[tf setBorderStyle:UITextBorderStyleRoundedRect]; 
[tf setDelegate:self]; 
[tf setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter]; 
[tf setEnabled:NO]; 
[tf setTag: tag]; 
[tf setText:@"0.0"]; 
[self insertSubview:tf atIndex:0]; 

return tf; 
} 

-(void)write:(id)sender { 
.... 
} 
+0

你的问题是....? – lnafziger

+0

我怎么做,我点击uitextfield和我的自定义键盘是显示在屏幕上像原来的键盘? –

+0

您可以将文本字段的inputView设置为您的自定义视图,当它成为第一个响应者时,它会自动为您显示键盘。请注意,行'[tf setEnabled:NO];'使它不会变得活跃,虽然.... – lnafziger

回答

0

在屏幕上的其他地方没有使用自己的键盘作为标准键盘的方法。

相关问题