允许 UIBarButtonItem 触摸顶部和顶部UINavigationBar 底部
看一下 Droplr iPhone 应用程序:
注意 UIBarButtonItem
的样子能够触摸屏幕/导航栏的右侧、左侧、顶部和底部吗?
我怎样才能实现类似的目标?以下是我如何制作一个示例 UIBarButton 并将其设置为正确的项目:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
button.frame= CGRectMake(0.0, 0.0, image.size.width, image.size.height);
[button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *bb = [[[UIBarButtonItem alloc] initWithCustomView:button]autorelease];
[self.navigationItem setRightBarButtonItem:bb animated:YES];
但是,它不右对齐,并且与顶部和底部有相当多的边距。底部。我的图像尺寸是正确的(44 像素),并且看起来它缩小了以适合各种框架。
那么,我该怎么做呢?
编辑:哎呀,顶部/底部间距是我的错。但是,我不知道如何将栏按钮与左/右侧对齐。这就是我的意思:(抱歉按钮丑陋,这只是一个测试)
我尝试设置图像插入,但它似乎没有做任何事情。
Take a look at the Droplr iPhone app:
Notice how the UIBarButtonItem
s are able to touch the right, left, top, and bottom of the screen/navigation bar?
How can I achieve something similar? Here's how I make a sample UIBarButton and set it to the right item:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
button.frame= CGRectMake(0.0, 0.0, image.size.width, image.size.height);
[button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *bb = [[[UIBarButtonItem alloc] initWithCustomView:button]autorelease];
[self.navigationItem setRightBarButtonItem:bb animated:YES];
However, it is not right aligned, and has quite a bit of margin from the top & the bottom. My image size is correct (44px), and it looks like it shrinks it to fit a frame of sorts.
So, how can I do this?
Edit: Whoops, the top/bottom spacing was my fault. However, I can't figure out how to align the bar button flush with the left/right side. Here's what I mean: (sorry for the ugly button, it was just a test)
I tried setting the image inserts, but it didn't seem to do anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 rightBarButtonItem 使用了 customView,并且使其右对齐。
只需尝试使用 CGRectMake-Numbers 作为 x 坐标,为了测试我添加了高数字......
I use a customView for the rightBarButtonItem and I get it right aligned.
Just try a bit with the CGRectMake-Numbers for the x-coordinate, for testing I added to high numbers...