我想在场景的导航栏中包含一个搜索栏。
使用此代码,我成功地将搜索栏放在导航栏中。
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(35, 0, 150, 40)];
self.navigationItem.titleView = titleView;
UISearchBar *mynewsb = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,150,40)];
mynewsb.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.0];
mynewsb.opaque = NO;
[self.navigationItem.titleView addSubview:mynewsb];
}
但是,当我运行该应用程序时,我得到了这个。
可以看到搜索栏的背景还是可以辨别的。它没有与 titleView 混合。顺便说一句,两个条形按钮项目是使用情节提要添加的。
我尝试了这些代码,但没有成功。
mynewsb.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.0];
mynewsb.opaque = NO;
为了将搜索栏背景与 titleView 很好地融合在一起,我该怎么做?