想要添加到 iPhone 中每个视图顶部的按钮
我想在 iPhone 应用程序中的每个视图顶部添加两个宽度分别为 133 像素和 150 像素、高度为 28 像素的按钮。只有此按钮栏下方的视图会发生变化,但是当发生导航时(推送弹出操作),我希望此栏也随其余视图一起滑动。 基本上,我希望应用程序的每个屏幕上都出现一个包含 2 个按钮的栏。请帮我。谢谢
I want to add two buttons of width 133 px and 150 px each and 28 px in height on top of every view in my iPhone app. Only the view below this button bar will change, but when navigation occurs (push pop operation), I want this bar also to slide with the remaining view.
basically, i want a bar containing 2 buttons to be present in ever screen of the app. Please help me. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您最好编写 UIViewController 的子类(例如将其称为
CustomUIViewController
)。在此类的 viewDidLoad 方法中,您可以根据需要添加视图,例如:
这应该可以工作(只要您记得在所有类中调用
[super viewDidLoad]
。现在您只需确保您正在视图控制器中子类化 CustomUIViewController 而不是 UIViewController
:
要使导航栏选项正常工作,请执行以下操作
You'd be best off writing a subclass of UIViewController (for instance call it
CustomUIViewController
).in the viewDidLoad method of this class you can add the view as appropriate eg:
That should work (as long as you remember to call
[super viewDidLoad]
in all your classes.Now you just have to make sure you're subclassing CustomUIViewController instead of UIViewController in your view controllers.
Edit
To get the navigation bar option to work do this:
我们将首先布置一个包含按钮的视图。在 Xcode 中,创建一个新的基于视图的 iPhone 应用程序,并将其命名为“GradientButtons”(或任何您想要的名称)。双击 GradientButtonsViewController.xib 资源以在 Interface Builder 中将其打开。
将 UIButton 控件从库拖到视图上。像这样设置它的属性:
We'll start by laying out a view containing buttons. In Xcode, create a new View-based iPhone application, and call it "GradientButtons" (or whatever you want). Double-click the GradientButtonsViewController.xib resource to open it in Interface Builder.
Drag a UIButton control from the library onto the view. Set its properties like this: