HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS 7 UIBarButtonItem荒谬的间距问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个问题,到目前为止我找不到解决方案.我正在为我的应用添加一个功能,并希望在我的UINavigationBar的左侧添加第二个UIBarButtonItem.出于某种原因,iOS 7将其作为button1,grandCanyon,button2.我找不到任何方法来消除这两个按钮之间的荒谬间距,这也导致我的标题不对齐.任何人都可以帮忙!?这个问题有方法解决吗!?

码:

UIBarButtonItem *firstButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imagenamed:@"firstButton"] style:UIBarButtonItemStylePlain target:self action:@SELEctor(showSetTings)];
UIBarButtonItem *secondButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imagenamed:@"secondButton"] style:UIBarButtonItemStylePlain target:self action:@SELEctor(showAttachments)];
[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:firstButton,secondButton,nil]];

解决方法

想想我已经设法使用如下所示的自定义视图来解决问题,它并不完美(例如选择使按钮变暗而不是更亮)但我明天会尝试修复它.很高兴我的头痛结束了!谢谢你的帮助,它引导我采取了一些我没试过的新方法.
UIImage *firstButtonImage = [UIImage imagenamed:@"firstButton"];
firstButtonImage = [firstButtonImage imageWithRenderingMode:UIImageRenderingModeAlwaystemplate];

UIButton *firstButton = [[UIButton alloc] initWithFrame:CGRectMake(0,35,35)];
[firstButton setImage:firstButtonImage forState:UIControlStateNormal];
[firstButton addTarget:self action:@SELEctor(firstButtonPressed) forControlEvents:UIControlEventTouchUpInside];

UIImage *secondButtonImage = [UIImage imagenamed:@"secondButton"];
secondButtonImage = [secondButtonImage imageWithRenderingMode:UIImageRenderingModeAlwaystemplate];

UIButton *secondButton = [[UIButton alloc] initWithFrame:CGRectMake(45,35)];
[secondButton setImage:secondButtonImage forState:UIControlStateNormal];
[secondButton addTarget:self action:@SELEctor(secondButtonPressed) forControlEvents:UIControlEventTouchUpInside];

UIView *leftBarItemsView = [[UIView alloc] initWithFrame:CGRectMake(0,80,35)];
[leftBarItemsView addSubview:firstButton];
[leftBarItemsView addSubview:secondButton];

UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarItemsView];

[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObject:leftBarItem]];

大佬总结

以上是大佬教程为你收集整理的iOS 7 UIBarButtonItem荒谬的间距问题全部内容,希望文章能够帮你解决iOS 7 UIBarButtonItem荒谬的间距问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。