- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
如何删除自定义左右 UINavigationBar 项左右的水平填充? iOS 默认设置的 padding 似乎有 ~ 10 点。
我正在自定义左右导航栏按钮(我已经放弃尝试设置自己的 backButtonItem,所以我只使用 leftBarButtonItem)。
在任何一种情况下(左或右),按下这些自定义按钮表明 Apple 似乎在 leftBarButtonItem 的左侧和 rightBarButtonItem 的右侧保留了一些填充;无论我将 UIButton 的自定义背景和图像属性设置多宽,我都将其放置在左/右栏按钮项中作为其自定义 View 。
由于 UIBarButtonItems 没有我可以访问的“框架”,我无法像普通 UIView 那样将它们定位在它们的 super View 中。
关于如何删除此默认填充的任何建议?请参阅所附的屏幕截图以查看我试图减小到零宽度的位。在屏幕截图中,加号图标向右移动,因为我给了它一个插图;但是突出显示的背景图像(也可能使用该插图)在其右侧被剪掉了)。
查看图片:https://skitch.com/starbaseweb/rj2e5/ios-simulator
作为引用,下面是我创建自定义 UIBarButtonItem 的方式(在本例中,它是右键):
- (UIBarButtonItem *)customAddButtonItemWithTarget:(id)target action:(SEL)action {
UIButton *customButtonView = [UIButton buttonWithType:UIButtonTypeCustom];
customButtonView.frame = CGRectMake(0.0f, 0.0f, 45.0f, 44.0f);
[customButtonView setBackgroundImage:
[UIImage imageNamed:@"bgNavBarButton-OutsideRight-Normal.png"]
forState:UIControlStateNormal];
[customButtonView setBackgroundImage:
[UIImage imageNamed:@"bgNavBarButton-OutsideRight-Highlighted.png"]
forState:UIControlStateHighlighted];
[customButtonView setImage:
[UIImage imageNamed:@"bgNavBarButton-Add-Normal.png"]
forState:UIControlStateNormal];
[customButtonView setImage:
[UIImage imageNamed:@"bgNavBarButton-Add-Highlighted.png"]
forState:UIControlStateHighlighted];
[customButtonView addTarget:target action:action
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customButtonItem = [[[UIBarButtonItem alloc]
initWithCustomView:customButtonView] autorelease];
[customButtonView setImageEdgeInsets:UIEdgeInsetsMake(0.0f, 10.0f, 0.0f, 0.0f)];
//customButtonItem.imageInsets = UIEdgeInsetsMake(0.0f, 10.0f, 0.0f, 0.0f);
return customButtonItem;
}
最佳答案
55正如上面所评论的,我采用的解决方案是基于对一个不同但非常相关的问题的回答:How to adjust UIToolBar left and right padding .它也由(并依赖于)iOS5 提供便利,它允许您在左侧或右侧设置多个按钮,而不仅仅是一个。
这是一个删除自定义左按钮项左侧填充的示例:
UIBarButtonItem *backButtonItem // Assume this exists, filled with our custom view
// Create a negative spacer to go to the left of our custom back button,
// and pull it right to the edge:
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -5;
// Note: We use 5 above b/c that's how many pixels of padding iOS seems to add
// Add the two buttons together on the left:
self.navigationItem.leftBarButtonItems = [NSArray
arrayWithObjects:negativeSpacer, backButtonItem, nil];
有了这个,导航栏中左侧栏按钮项的左侧填充消失了!
注意:这对我在 iOS5 和 iOS6 中有效。鉴于 iOS7 与公开演示有很大不同,那些拥有 iOS7 早期种子的人应该测试一些无意的东西,比如这个 hack,是否会在 iOS6 之后继续为你工作。
关于iphone - 将基于自定义 View 的 UIBarButtonItem 放置在没有默认水平填充的导航栏中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4715280/
我有一个简单的 UITableViewController 和一个 NavigationController 作为 Root View Controller 。我在导航栏中添加了“选项”UIBarBu
我正在尝试 this Apple tutorial但我发现了一个错误。有人可以帮助我吗? Disable Saving When the User Doesn't Enter an Item Name
我有一个 UIBarButtonItem 和 UIButton 作为自定义 View 。 UIButton 上有一个 addTarget:action:。在 Action 中,我展示了一个弹出窗口。我
我正在学习 iOS 开发,有两个简单且相关的问题: 1. 如何将多行项目添加到一个 UIToolBar 中,这可能吗?我想要一个 UISearchBar 和一个 UIToolbar 上的两行 UIBa
这就是我自定义 UIBarButtonItem 的方式: if DBAppSettings.imageViewForCartBarButtonItem == nil { DBAppSettin
有没有办法让UIBarButtonItem独家触摸?目前,您可以同时选择多个,但它不断使我的应用程序崩溃。 最佳答案 比继承导航栏更简单的方法,但思路相同; for(UIView *temp in s
如何在 uitoolbar 内旋转 uibarbuttonitem?因为我旋转了 uitoolbar(现在是垂直的)并且我的栏按钮项目也旋转了,但我不希望这样。 谢谢 最佳答案 UIBarButton
我创建了一个具有半透明黑色样式的工具栏,如下所示: UIToolbar *toolbar = [UIToolbar new]; toolbar.barStyle = UIBarStyleBlack;
有没有办法以动画方式启用或禁用按钮?我尝试了以下方法但没有成功。我猜测此时启用的属性无法像不透明度一样进行动画 - 但我希望我是错的。 [UIView beginAnimations:nil
在 IB 中,我可以选择一个 UIBarButtonItem,将其设置为“普通”、“自定义”并应用图像,它在 UIToolbar 或 UINavigationBar 中看起来不错。 当我尝试在代码中执
我需要更改 UIBarButtonItem 标题的字体。目前是 barbuttonItem.customView = customLabel。现在我希望添加一个选择器和目标,以便我可以获得 touch
我正在尝试偏移应用程序中的 UIBarButtonItems,由于我用于导航栏的图像,我需要它们稍微偏移,以便它们全部正确排列。我已经成功地做到了这一点: [[UINavigationBar appe
我希望使用标签访问 UIToolbar 上的 UIBarButtonItem。代码如下所示 UIBarButtonItem *myBarButtonItem=(UIBarButtonItem*)myU
我有一个自定义按钮,我想添加到导航栏上。到目前为止,这就是我的 RootViewController 中的内容(它继承了 UIViewController,UINavigationController
每当“userInput”UITextField 中没有输入时,我尝试禁用我的发送按钮(工具栏中的 UIBarButtonItem),并在有输入时启用它。这是我写的代码 - 我不太明白为什么它不起作用
我添加了一个 UIToolbar 实例和其顶部的按钮。每个按钮都属于 UIBarButtonItem 类。 我的要求是每个按钮都有一个自定义布局,我不想使用Apple提供的原生按钮样式。所以我在 In
你能看到按钮左边的距离吗?如何消除这个距离? 最佳答案 在按钮左侧添加一个间隔符,例如: UIBarButtonItem *backButtonItem = ....; UIBarButtonItem
我知道有些人已经问过这个问题,但到目前为止,答案还不是很具体。 显然苹果已经使导航栏的点击区域比实际更大,但我认为它不应该那么大。 在我的应用程序中,导航栏正下方有一个 TableView,您可以一直
我已经为 UINavigationBar 设置了自定义色调颜色(在 UINavigationController 内),这又为 UIBarButtonItems 设置适当的匹配颜色。插入 UINavi
我有一个带有两个 View 的导航栏应用程序:父 View 和 subview 。在 subview 中,我在右上角添加一个按钮,如下所示: - (void)viewDidLoad { UIB
我是一名优秀的程序员,十分优秀!