这是我的主要代码:
- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; self.navigationController.interactivePopGestureRecognizer.enabled = YES; self.navigationController.interactivePopGestureRecognizer.delegate = self; self.navigationItem.rightbarbuttonItems = @[[self negativeSpacerWithWIDth:5],[self rightbutton]]; self.navigationItem.leftbarbuttonItems = @[[self negativeSpacerWithWIDth:5],[self leftbutton]];}- (UIbarbuttonItem *)leftbutton { UIbutton *button = [[UIbutton alloc] initWithFrame:CGRectMake(0,35,35)]; [button setimage:[UIImage imagenamed:@"icon_app_back_normal"] forState:UIControlStatenormal]; [button addTarget:self action:@selector(back) forControlEvents:UIControlEventtouchUpInsIDe]; UIbarbuttonItem *item = [[UIbarbuttonItem alloc] initWithCustomVIEw:button]; return item;}- (UIbarbuttonItem *)rightbutton { UIbutton *button = [[UIbutton alloc] initWithFrame:CGRectMake(0,35)]; [button setimage:[UIImage imagenamed:@"setting"] forState:UIControlStatenormal]; UIbarbuttonItem *item = [[UIbarbuttonItem alloc] initWithCustomVIEw:button]; return item;}- (UIbarbuttonItem *)negativeSpacerWithWIDth:(CGfloat)wIDth { UIbarbuttonItem *spacer = [[UIbarbuttonItem alloc] initWithbarbuttonSystemItem:UIbarbuttonSystemItemFixedspace target:nil action:nil]; [spacer setWIDth:wIDth]; return spacer;}解决方法 将Fixedspace barbuttonItem添加到barbuttonItem数组时,这似乎是一个错误.如果要将偏移设置为导航项,可能必须使用其他方式,例如更改按钮的imageEdgeInsets.
- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; // Do not set Fixed Space type button item. self.navigationItem.leftbarbuttonItem = [self leftbutton]; self.navigationItem.rightbarbuttonItem = [self rightbutton]; // It work too //self.navigationItem.leftbarbuttonItems = @[[self leftbutton],[self leftbutton]]; //self.navigationItem.rightbarbuttonItems = @[[self rightbutton],[self rightbutton]]; self.navigationController.interactivePopGestureRecognizer.enabled = YES; self.navigationController.interactivePopGestureRecognizer.delegate = self;}- (UIbarbuttonItem *)leftbutton{ UIbutton *button = [[UIbutton alloc] initWithFrame:CGRectMake(0,35)]; //... // to add offset you want button.imageEdgeInsets = UIEdgeInsetsMake(0,-15,15); UIbarbuttonItem *item = [[UIbarbuttonItem alloc] initWithCustomVIEw:button]; return item;}- (UIbarbuttonItem *)rightbutton{ UIbutton *button = [[UIbutton alloc] initWithFrame:CGRectMake(0,15,-15); UIbarbuttonItem *item = [[UIbarbuttonItem alloc] initWithCustomVIEw:button]; return item;}总结
以上是内存溢出为你收集整理的如何处理iOS 11导航BarButtonItems错误?全部内容,希望文章能够帮你解决如何处理iOS 11导航BarButtonItems错误?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)