简体   繁体   中英

iOS navigationItem.titleView remove margins

I have something like this:

titleBar_image

But I need that the view that am setting for the titleView, doesn't has those margins on the left and right side. Something like this:

titleBar_image2

This is what am actually doing:

@property (nonatomic, strong) XHScrollMenu *scrollMenu; // where XHScrollMenu is a subclass of UIView

- (void)viewdidLoad{
 _scrollMenu = [[XHScrollMenu alloc] initWithFrame:self.navigationController.navigationBar.frame];
 _scrollMenu.backgroundColor = [UIColor clearColor];
 _scrollMenu.delegate = self;
 _scrollMenu.selectedIndex = 0;
 self.navigationItem.titleView =self.scrollMenu;
}

I tried giving the view a with of 320, but I got the same result. I read in other post, that maybe a subclass make the trick, but don't know how to implement that solution...

How can I make the title view use the entire width?

Try with bounds instead of frame . see different between bounds and frame.

...initWithFrame:self.navigationController.navigationBar.bounds] /// or give frame manually such like CGRectMake(x,y,self.view.frame.size.width, yourHeight);

If this suggestion doesn't help you then sure problem under initWithFrame of XHScrollMenu . Go in this method and check there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM