ios - UIAutomation中如何识别添加到UIButton的 subview (imageviews)?

标签 ios objective-c iphone instruments ios-ui-automation

我有一个 UIButton 并且按钮 background 设置为 image。添加 按钮右上角的 image view 我设置了它 单击按钮以显示选择时显示为不同的图像。

当我尝试使用 instruments自动化时。我没有看到任何 subviews UIAutomator 中的 (image views)。logElementTree() 方法不显示 任何 ImageView

如何识别在 UIButton 中添加为 subviewimage view

这是代码。

 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
 button.frame = CGRectMake(40, 40, 100, 100);
 [button addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
 [button setBackgroundImage:[UIImage imageNamed:@“testImage.png”] forState:UIControlStateNormal];
 UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
 imageview.frame = CGRectMake(70,30,20,20);
 [button addSubview:imageview];

最佳答案

您必须设置 accessibilityEnabled 和 accessibilityLabel。

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(40, 40, 100, 100);
[button addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];

button.accessibilityEnabled = YES;
button.accessibilityLabel =@"My Button";

[button setBackgroundImage:[UIImage imageNamed:@“testImage.png”] forState:UIControlStateNormal];


UIImageView *imageview = [[UIImageView alloc] initWithImage:image];

imageview.accessibilityEnabled = YES;
imageview.accessibilityLabel = @"My Image";

imageview.frame = CGRectMake(70,30,20,20);
[button addSubview:imageview];

enter image description here

Refer this tutorial

关于ios - UIAutomation中如何识别添加到UIButton的 subview (imageviews)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25301076/

相关文章:

iphone - iOS 应用程序因查询电子邮件按钮而被拒绝

ios - JSON解码到字典

ios - 允许 JSONDecoder() 接受空数组作为空字典

iOS NSDateFormatter 从字符串返回错误的日期

objective-c - 如何在子类中复制NSArray内存语义

objective-c - UITableViewCell中的文本居中对齐问题

ios - 如何快速观察firebase数据库中子子节点的值变化?

ios - 将 CGAffineTransformScale 与 UIAttachmentBehavior (UIDynamicAnimator) 结合使用

iOS - 从一个 View Controller 传递数据以在另一个 View Controller 的 init 方法中使用

ios - 如何在 iOS 中通过 Twitter API 获取用户电子邮件地址?