我正在尝试将文本字段添加到导航栏中,但它没有显示在模拟器中。我在 viewdidload 中按如下方式执行:
UITextView *textField = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 170, 44)];
self.navigationItem.titleView = textField;
有任何想法吗?
Thanks!
我已经这样做了。我知道到目前为止你已经得到了答案
但这仍然对其他人有帮助所以
这可以按如下方式完成
-(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];
}
当 viewdidunload 时,请不要忘记从超级视图中删除
- (void)viewDidUnload
{
[super viewDidUnload];
[textfieldTxt removeFromSuperview];
[imgVw removeFromSuperview];
}
thanks
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)