Objective C如何添加textfield到导航栏 [英] Objective C how to add textfield into navigation bar
本文介绍了Objective C如何添加textfield到导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将一个文本字段添加到导航栏,但它不会显示在模拟器中。我在viewdidload里面这样做:
I'm trying to add a textfield into a navigation bar, but it doesn't show up in the simulator. I do it as follows inside viewdidload:
UITextView *textField = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 170, 44)];
self.navigationItem.titleView = textField;
任何想法?
谢谢! / p>
Thanks!
推荐答案
我已经这样做了。我知道你已经得到了回答现在
,但仍然这将有助于别人所以
这可以做如下
i have done it in this way. i know that you have got to the answer uptil now but still this will helpful to someone else so this can be done as follows
-(void)viewWillAppear:(BOOL)animated
{
imgVw =[[UIImageView alloc]initWithFrame:CGRectMake(68, 7, 180, 28)];
[imgVw setImage:[UIImage imageNamed:@"textfieldBackground.png"]];
[self.navigationController.navigationBar addSubview:imgVw];
textfieldTxt = [[UITextField alloc]initWithFrame:CGRectMake(78, 11, 170, 25)];
textfieldTxt.backgroundColor = [UIColor clearColor];
[textfieldTxt setAutocorrectionType:UITextAutocorrectionTypeNo];
textfieldTxt.delegate = self;
[self.navigationController.navigationBar addSubview:textfieldTxt];
}
请不要忘记从superview中删除,当viewdidunload
please don't forgot to remove from superview, when viewdidunload
- (void)viewDidUnload
{
[super viewDidUnload];
[textfieldTxt removeFromSuperview];
[imgVw removeFromSuperview];
}
感谢
这篇关于Objective C如何添加textfield到导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文