以编程方式在 ARKit 中自定义 uibutton

发布于 2024-09-18 15:23:43 字数 1447 浏览 8 评论 0原文

我正在使用 ARKit API ...我想在右侧的框中添加自定义 UIButton,该按钮出现在由应用程序委托中的以下代码生成的屏幕上:

#define BOX_WIDTH 350
#define BOX_HEIGHT 150

- (UIView *)viewForCoordinate:(ARCoordinate *)coordinate {

    CGRect theFrame = CGRectMake(0, 0, BOX_WIDTH, BOX_HEIGHT);
    UIView *tempView = [[UIView alloc] initWithFrame:theFrame];

    //tempView.backgroundColor = [UIColor colorWithWhite:.5 alpha:.3];

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, BOX_WIDTH, 20.0)];
    titleLabel.backgroundColor = [UIColor colorWithWhite:.3 alpha:.8];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = UITextAlignmentCenter;
    titleLabel.text = coordinate.title;
    [titleLabel sizeToFit];

    titleLabel.frame = CGRectMake(BOX_WIDTH / 2.0 - titleLabel.frame.size.width / 2.0 - 4.0, 0, titleLabel.frame.size.width + 8.0, titleLabel.frame.size.height + 8.0);

    UIImageView *pointView = [[UIImageView alloc] initWithFrame:CGRectZero];
    pointView.image = [UIImage imageNamed:@"location.png"];
    pointView.frame = CGRectMake((int)(BOX_WIDTH / 2.0 - pointView.image.size.width / 2.0), (int)(BOX_HEIGHT / 2.0 - pointView.image.size.height / 2.0), pointView.image.size.width, pointView.image.size.height);

    [tempView addSubview:titleLabel];
    [tempView addSubview:pointView];

    [titleLabel release];
    [pointView release];

    return [tempView autorelease];
}

如何实现此目的?请帮忙!

I am playing around with the ARKit API ...I wanted to add Custom UIButton within the box on the right side which appears on the screen generated by the code below in the app delegate :

#define BOX_WIDTH 350
#define BOX_HEIGHT 150

- (UIView *)viewForCoordinate:(ARCoordinate *)coordinate {

    CGRect theFrame = CGRectMake(0, 0, BOX_WIDTH, BOX_HEIGHT);
    UIView *tempView = [[UIView alloc] initWithFrame:theFrame];

    //tempView.backgroundColor = [UIColor colorWithWhite:.5 alpha:.3];

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, BOX_WIDTH, 20.0)];
    titleLabel.backgroundColor = [UIColor colorWithWhite:.3 alpha:.8];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = UITextAlignmentCenter;
    titleLabel.text = coordinate.title;
    [titleLabel sizeToFit];

    titleLabel.frame = CGRectMake(BOX_WIDTH / 2.0 - titleLabel.frame.size.width / 2.0 - 4.0, 0, titleLabel.frame.size.width + 8.0, titleLabel.frame.size.height + 8.0);

    UIImageView *pointView = [[UIImageView alloc] initWithFrame:CGRectZero];
    pointView.image = [UIImage imageNamed:@"location.png"];
    pointView.frame = CGRectMake((int)(BOX_WIDTH / 2.0 - pointView.image.size.width / 2.0), (int)(BOX_HEIGHT / 2.0 - pointView.image.size.height / 2.0), pointView.image.size.width, pointView.image.size.height);

    [tempView addSubview:titleLabel];
    [tempView addSubview:pointView];

    [titleLabel release];
    [pointView release];

    return [tempView autorelease];
}

How can I pull this off ? Please help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

獨角戲 2024-09-25 15:23:43

这是我的代码:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(190, 430, 110, 30);
[button setTitle:@"Retour au plan" forState:UIControlStateNormal];
[button addTarget:self action:@selector(boutonPlan)
 forControlEvents:UIControlEventTouchUpInside];

// Si il peut, on effectue la MAJ de la vue
ParkingAppDelegate *appDelegate = (ParkingAppDelegate *)[[UIApplication sharedApplication] delegate];
arvc = [[ARViewController alloc] initWithDelegate:self];
//add the button to the view
[arvc.view addSubview:button];

希望有帮助。

Here's my code :

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(190, 430, 110, 30);
[button setTitle:@"Retour au plan" forState:UIControlStateNormal];
[button addTarget:self action:@selector(boutonPlan)
 forControlEvents:UIControlEventTouchUpInside];

// Si il peut, on effectue la MAJ de la vue
ParkingAppDelegate *appDelegate = (ParkingAppDelegate *)[[UIApplication sharedApplication] delegate];
arvc = [[ARViewController alloc] initWithDelegate:self];
//add the button to the view
[arvc.view addSubview:button];

Hope this helps.

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