UINavigationBar 的问题
我在这方面有很多问题。
- 首先,UINavigationController 内置的 UINavigationBar 将其余 UIViewController 的位置向下移动(我必须手动将位置向上移动)。我在 stackoverflow 上搜索过,一个建议是隐藏当前导航栏并在界面生成器中手动添加 UINavigationBar。这让我想到了第二个问题:
- 如果我通过 IB 手动添加 UINavigationBar,导航就会“断开”,例如,需要手动实现后退按钮才能弹出视图控制器。这让我想到了第三个问题:
- 我得到的规范表明它需要具有后退按钮形状的后退按钮(按钮的左侧像三角形一样倾斜)。不幸的是,我到处搜索,每个人都说你必须手动添加图像才能使其看起来像后退按钮。但是如果我的后退按钮标题比图像长怎么办?我必须为每个标题制作一个图像!
任何解决其中任何 3 个问题的方法都会非常有帮助!
I'm having so many problems with this.
- First of all, the UINavigationBar built-in from the UINavigationController nudges the position of the rest of my UIViewControllers down (which I have to manually nudge the position back up). I've searched on stackoverflow and one suggestion says to hide the current navbar and manually add a UINavigationBar in the interface builder. Which brings me to my second problem:
- If I add a UINavigationBar manually through IB, the navigation becomes "disconnected", for example, the back button needs to be implemented manually to pop view controllers. Which brings me to my third problem:
- The specification I was given stated that it wants the back button with the shape of a back button (left of the button is slanted like a triangle). Unfortunately I've been searching everywhere and everyone is saying you'll have to manually add an image to make it look like a back button. But what if my back button title is longer than the image? I would have to make an image for each title!
Any solutions to any 3 of those problems would be extremely helpful!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第一个问题:我使用 415 像素的父视图,因为导航栏占用了 45 (460-415) 个像素。自从我从 415 开始以来,不需要轻推。
第二和第三:不是真的。您可以在绘制文本时使用可拉伸图像。对于此配方,您需要一个具有左侧和右侧的按钮,以及中间一个像素,该像素将被拉伸到(左侧+右侧+中间文本的长度)的大小。
示例:左按钮 12 + 1 +(文本大小)+ 5 像素
然后执行此操作:
请注意,我' m 使用系统字体,如果您想要不同的字体,请添加另一个参数。然后在控制器的 viewLoad 上添加以下内容:
我们用这段代码实现了什么?尺寸完美的按钮,可与任何本地化字符串配合使用,并且无需为每种支持的语言生成 2x PNG(普通 + 视网膜)。这类似于 UIKit 用于绘制带有标题的按钮的 Core Graphics 代码,因此它不会减慢您的 UI 速度。
First problem: I use a parent view with 415 pixels because 45 (460-415) are taken by the nav bar. No need to nudge since I start with 415.
Second and third: not really. You can use a stretchable image where you draw the text. For this recipe you need a button with a left and right side, and one pixel in the middle which will be stretched to the size of the (left side + right side + length of the text in the middle).
Example: left button with 12 + 1 + (text size) + 5 pixels
Then do this:
Note that I'm using the system font, if you want something different, add another parameter. And then you add the following on the viewLoad of your controller:
What do we achieve with this code? perfectly sized buttons that work with any localized string, and saves you from generating 2x PNG (normal + retina) for each language supported. This is similar to the Core Graphics code UIKit uses to paint buttons with title so it's not going to slow down your UI.
在 XIB 中,您必须设置 UIView 的导航栏样式和状态栏样式(在 UiViewController.xib 中)才能看到实际布局。
如果您想关闭导航栏,那么当您要将其添加到窗口上时,可以调整 UINavigationController 视图的框架。但在这里你必须照顾 UINavigationController 堆栈下每个 UIViewController 的下部。
In XIB, You have to set Navigation Bar style and status bar style of a UIView(in UiViewController.xib) to see the actual layout.
If You want to bring down the navigation bar, then So can adjust the frame of UINavigationController view when you are going to add it on window. bUt here you have to take care of lower part of each UIViewController under UINavigationController stack.
这是一连串的问题。不过,我有一个简单的答案。
UIViewController 这称为
wantsFullScreenLayout
。对于要添加到导航堆栈的每个视图控制器,将其设置为YES,它们将忽略存在导航栏的事实。只需记住相应地设置子视图的框架即可。这纠正了你的第一个问题。其余问题的解决方案之后你就会自然而然地找到。
That's a cascade of problems. I have a simple answer, however.
There's a nifty little property of UIViewController that's called
wantsFullScreenLayout
. Set it to YES for every view controller that you want to add to the navigation stack and they will ignore the fact that there is a navigation bar. Just remember to set the frames of your subviews accordingly.This corrects your first problem. The solution to the rest should come naturally to you afterwards.