gpt4 book ai didi

iphone - 如何以编程方式使 UIToolbar 覆盖?

转载 作者:行者123 更新时间:2023-11-28 22:52:33 26 4
gpt4 key购买 nike

我的大部分相机覆盖屏幕都被不透明的覆盖层覆盖。对于剩余部分,我想添加一个带有多个按钮的 UIToolbar。请务必提及如何以编程方式使这些按钮也可点击!

这是我添加叠加层的方式,它看起来很完美。

- (UIView*)CommomOverlay  {
//Both of the 428 values stretch the overlay bottom to top for overlay function. It doesn't cover it.
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,428)];
UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,428)];
[FrameImg setImage:[UIImage imageNamed:@"newGraphicOverlay.png"]];
[view addSubview:FrameImg];
return view;
}

同样,我将如何添加一个工作工具栏(可点击且功能齐全,上面有 2 个按钮)?

最佳答案

试试这个:(在您的 viewDidLoad 或 viewWillAppear 中)

//create toolbar and set origin and dimensions
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 428, 320, 32)];

//create buttons and set their corresponding selectors
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(button1Tap:)];
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(button2Tap:)];

//if you want custom icons, use something like this:
UIBarButtonItem *button3 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon1_portrait.png"] landscapeImagePhone:[UIImage imageNamed:@"icon1_landscape.png"] style:UIBarButtonItemStylePlain target:self action:@selector(button3Tap:)];

//add buttons to the toolbar
[toolbar setItems:[NSArray arrayWithObjects:button1, button2, nil]];

//add toolbar to the main view
[self.view addSubview:toolbar];
  • 像这样创建选择器:

    -(void)button1Tap:(id)sender {
    NSLog(@"Button 1 was tapped!");
    // do whatever needs to happen
    }

关于iphone - 如何以编程方式使 UIToolbar 覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11589085/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com