Kerberos Kerberos - 1 year ago 151
Objective-C Question

Obj-C - How to add a menu bar on map

I would like to create a menu bar on a map like in the bottom of the image.
It has a search bar on the top and three buttons on the bottom.
How can I join the buttons with the searchbar like in the image?

enter image description here

Answer Source

you can make a customize view add to self.view and bringTop the view.

here is the sample code :

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

CGFloat margin = 10;
CGFloat viewWidth = self.view.frame.size.width - 2 * margin;
CGFloat viewHeight = 82;

UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(margin, SCREEN_HEIGHT - viewHeight - margin, viewWidth, viewHeight)];
toolView.backgroundColor = [UIColor grayColor];

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, viewWidth, 40)];
[toolView addSubview:searchBar];

CGFloat btnWidth = (viewWidth - 4) / 3;
CGFloat btnHeight = 40;

for (NSInteger i = 0; i < 3; i ++) {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:[NSString stringWithFormat:@"%ld btn", i+1] forState:UIControlStateNormal];
    [toolView addSubview:btn];
    [btn setBackgroundColor:[UIColor blackColor]];
    btn.frame = CGRectMake(i *(btnWidth + 1), 42, btnWidth, btnHeight);

[self.view addSubview:toolView];
[self.view bringSubviewToFront:toolView];

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download