想要添加到 iPhone 中每个视图顶部的按钮

发布于 2024-10-05 04:05:35 字数 158 浏览 1 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光磨忆 2024-10-12 04:05:35

您最好编写 UIViewController 的子类(例如将其称为 CustomUIViewController)。

在此类的 viewDidLoad 方法中,您可以根据需要添加视图,例如:

- (void)viewDidLoad {
    UIView *bar = [[[UIView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,28)] autorelease];
    UIButton *buttonOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    // etc...
    [bar addSubview:buttonOne];
    UIButton *buttonTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    // etc...
    [bar addSubview:buttonTwo];

    [self.view insertSubview:bar atIndex:0];
}

这应该可以工作(只要您记得在所有类中调用 [super viewDidLoad]

现在您只需确保您正在视图控制器中子类化 CustomUIViewController 而不是 UIViewController

要使导航栏选项正常工作,请执行以下操作

    UIBarButtonItem *cancel = [[[UIBarButtonItem alloc] initWithTitle:@"Cancelsdkjfnsdjfhksdjfhks" style:UIBarButtonItemStylePlain target:self action:@selector(cancel:)] autorelease];
    [self.navigationItem setLeftBarButtonItem:cancel];
    UIBarButtonItem *send = [[[UIBarButtonItem alloc] initWithTitle:@"Senddsfsdfsdfsdfsdfsdf" style:UIBarButtonItemStylePlain target:self action:@selector(send:)] autorelease];
    [self.navigationItem setRightBarButtonItem:send];

    self.navigationItem.titleView = [[[UIView alloc] init] autorelease];

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:

- (void)viewDidLoad {
    UIView *bar = [[[UIView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,28)] autorelease];
    UIButton *buttonOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    // etc...
    [bar addSubview:buttonOne];
    UIButton *buttonTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    // etc...
    [bar addSubview:buttonTwo];

    [self.view insertSubview:bar atIndex:0];
}

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:

    UIBarButtonItem *cancel = [[[UIBarButtonItem alloc] initWithTitle:@"Cancelsdkjfnsdjfhksdjfhks" style:UIBarButtonItemStylePlain target:self action:@selector(cancel:)] autorelease];
    [self.navigationItem setLeftBarButtonItem:cancel];
    UIBarButtonItem *send = [[[UIBarButtonItem alloc] initWithTitle:@"Senddsfsdfsdfsdfsdfsdf" style:UIBarButtonItemStylePlain target:self action:@selector(send:)] autorelease];
    [self.navigationItem setRightBarButtonItem:send];

    self.navigationItem.titleView = [[[UIView alloc] init] autorelease];
寄意 2024-10-12 04:05:35

我们将首先布置一个包含按钮的视图。在 Xcode 中,创建一个新的基于视图的 iPhone 应用程序,并将其命名为“GradientButtons”(或任何您想要的名称)。双击 GradientButtonsViewController.xib 资源以在 Interface Builder 中将其打开。

将 UIButton 控件从库拖到视图上。像这样设置它的属性:

* Change the type to "Custom"
* Set the title to "Gray"
* Change the text color to white
* Change the background color to gray

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:

* Change the type to "Custom"
* Set the title to "Gray"
* Change the text color to white
* Change the background color to gray
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文