How to set the title of UIToolBar?

后端 未结 8 1143
独厮守ぢ
独厮守ぢ 2021-02-01 07:09

How can I set the title of UIToolBar such that it looks the same as the title in UINavigationBar?

I tried to use a button with plain style, it looks ok, but it will be

8条回答
  •  清歌不尽
    2021-02-01 07:40

    This solves the highlighting problem, disabled problem, and touch problem.

    Toolbar and titleButton were both created in IB. The view title is covered by the toolbar. So put the title in a toolbar.

    self.titleButton.title = @"Order";  // myInterestingTitle
    

    It looks like this: enter image description here

    Disable to prevent any highlighting, and to stop it from responding to touches.

    self.titleButton.enabled=NO;
    

    Then it looks like this:enter image description here

    It will look disabled, so set the color for disabled to white, which has an implicit alpha=1.0. This effectively overrides the 'disabled' look.

    [self.titleButton setTitleTextAttributes:
            [NSDictionary dictionaryWithObject:[UIColor whiteColor]
                                        forKey:UITextAttributeTextColor]
                                    forState:UIControlStateDisabled ];
    

    Here's what you get: enter image description here

提交回复
热议问题