我与UINavigationBar有一个视图
导航栏只允许我在固定位置使用按钮
固定位置在导航栏的两侧..
我想自定义按钮的位置...任何Idea...will帮我提前感谢
发布于 2011-09-09 22:10:13
您不能自定义按钮在UINavigationItem上的位置,您只能设置rightBarButtonItem和leftBarButtonItem。
如果您确实需要这样做,请考虑使用工具栏。
如果需要像导航栏的后退按钮一样的后退按钮,请创建自定义按钮并使用图像。
这里有一个PSD将会有所帮助。
发布于 2011-09-10 00:05:38
您可以在UINavigationItem中定位自定义按钮。下面是我如何在右侧添加三个按钮的方法:
// create a toolbar to have three buttons in the right (thanks Mart!)
tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 157, 44.01)];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 1.0, 157.0, 44.1)];
[imgView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"NavigationBarBackground" ofType:@"png"]]];
[tools addSubview:imgView];
[tools sendSubviewToBack:imgView];
[tools setTintColor:[UIColor colorWithRed:127/255.0 green:184/255.0 blue:72/255.0 alpha:1.0]];
[imgView release];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
UIBarButtonItem* bi = [[UIBarButtonItem alloc]
initWithTitle:@"Filter" style:UIBarButtonItemStyleBordered target:self action:@selector(showFilter:)];
[buttons addObject:bi];
[bi release];
bi = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"Map.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showMap:)];
[buttons addObject:bi];
[bi release];
bi = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"Favourite.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(saveSearch:)];
[buttons addObject:bi];
[bi release];
[tools setItems:buttons animated:NO];
[buttons release];
rightBarButton = nil;
rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:tools];
self.navigationItem.rightBarButtonItem = rightBarButton;https://stackoverflow.com/questions/7362749
复制相似问题