sud*_*-rf 8 iphone cocoa-touch uinavigationbar uibarbuttonitem
看看Droplr iPhone应用程序:

请注意UIBarButtonItems 如何触摸屏幕/导航栏的右侧,左侧,顶部和底部?
我怎样才能达到类似的效果?以下是我如何制作示例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];
Run Code Online (Sandbox Code Playgroud)
但是,它没有正确对齐,并且从顶部和底部有相当多的余量.我的图像尺寸是正确的(44像素),它看起来像缩小它以适应各种框架.
那么,我该怎么做呢?
编辑:哎呀,顶部/底部间距是我的错.但是,我无法弄清楚如何将条形按钮与左/右侧齐平.这就是我的意思:(抱歉丑陋的按钮,这只是一个测试)

我尝试设置图像插入,但似乎没有做任何事情.
Qui*_*rin 11
UIView *rightview = [[UIView alloc] initWithFrame:CGRectMake(0,0,30,30)];
UIButton *searchbutton = [[UIButton alloc] initWithFrame:CGRectMake(2,2,50, 30)];
[searchbutton setImage:[UIImage imageNamed:@"some-pic.png"] forState: UIControlStateNormal];
[rightview addSubview:searchbutton];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:rightview];
self.navigationItem.rightBarButtonItem = customItem;
[customItem release];
Run Code Online (Sandbox Code Playgroud)
我为rightBarButtonItem使用了一个customView,我把它对齐了.只需尝试使用CGRectMake-Numbers作为x坐标,测试我添加到高数字......
| 归档时间: |
|
| 查看次数: |
2396 次 |
| 最近记录: |