我有一个小问题,我的 uicollectionviewcontroller 顶部栏没有出现在模拟器和设备中。我已经将顶部栏设置为 uicollectionviewcontroller 的半透明导航栏,然后我将导航项拖到导航栏,最后我为左栏按钮项设置了一个图像以用作后退按钮。下面是截图。
顶栏 Storyboard:
模拟器结果:
最佳答案
看起来您没有导航 Controller ,要在没有导航 Controller 控制 View 层次结构的情况下以编程方式添加导航栏,您可以执行以下操作。
-(void) viewWillAppear:(BOOL)animated {
UINavigationBar *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[UINavigationBar appearance].barTintColor = [UIColor lightGrayColor];
[self.view addSubview: navBar];
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
style:UIBarButtonItemStyleBordered
target:self
action:nil];
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered
target:self action:nil];
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"Navigation Title"];
navItem.rightBarButtonItem = doneItem;
navItem.leftBarButtonItem = cancelItem;
navBar.items = [NSArray arrayWithObjects: navItem,nil];
[UIBarButtonItem appearance].tintColor = [UIColor blueColor];
}
关于ios - UICollectionView 顶部栏未出现在模拟器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33812253/