开发者

iOS: Is is possible to make a UINavigationBar taller and "push" the other views down the screen?

Is there a way to make the "content" area of an iPhone app aware of a larger navigation bar?

Similar to these questions:

  • iOS: Adding a fixed image just开发者_如何学Python below the navigation bar
  • iOS: Positioning navigation bar buttons within custom navigation bar

I've managed to use the 1st questions sample code to add a category on UINavigationBar and change its height, and added a subview where I need it, but I can't see a way to cause the UITableView (or indeed any content views) to take its height into consideration:

iOS: Is is possible to make a UINavigationBar taller and "push" the other views down the screen?

(The colors are only to make the different views distinguishable)


The accepted answer to the first question sets the nav bar's frame in -layoutSubviews, which is anywhere from "ewwwww" to outright wrong depending on the assumptions made by other layout code.

Instead, override -sizeThatFits: to return a more appropriate size.


I'd go about this by adjusting the tableView.frame, so something like this:

CGRect navFrame = self.navigationController.navigationBar.frame;

CGRect tableFrame = self.tableView.frame;

tableFrame.size.height = tableFrame.size.height - navFrame.size.height;
tableFrame.origin.y = navFrame.size.height; //move it down by the height covered by the navigation Bar

self.tableView.frame = tableFrame;

You could do this with your other views as well - i.e. by simply adjusting the frame.

I've not got XCode on this computer, so I've not checked the code - just written it out as an example, so please check it yourself before using it!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜