putting labels, buttons on the navigation bar iOS

前端 未结 5 1683
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 11:59

I have created custom navigation controller,

I want to be added, a date at the left, a back button on the right and the title next to back button.

I tried to

5条回答
  •  失恋的感觉
    2021-01-13 12:43

    add custom view in UIToolbar

     UIToolbar *tools = [[UIToolbar alloc]
                            initWithFrame:CGRectMake(0.0f, 0.0f,190.0f, 44.01f)]; 
    
        tools.barStyle = -1; // clear background
        NSMutableArray *buttons = [[NSMutableArray alloc] init];
    
        UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        bi.width =10.0f;
        [buttons addObject:bi];
        [buttons addObject:add your view];
        bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        bi.width =10.0f;
        [buttons addObject:bi];
        [buttons addObject:add your view];
        [tools setItems:buttons animated:NO];
        UIBarButtonItem *buttons_ = [[UIBarButtonItem alloc] initWithCustomView:tools];
        self.navigationItem.rightBarButtonItem = buttons_; //same to leftBarButtonItem
    

提交回复
热议问题