我有一个 UIButton
并且按钮 background
设置为 image
。添加
按钮右上角的 image view
我设置了它
单击按钮以显示选择时显示为不同的图像。
当我尝试使用 instruments
来自动化
时。我没有看到任何 subviews
UIAutomator
中的 (image views
)。logElementTree()
方法不显示
任何 ImageView
。
如何识别在 UIButton
中添加为 subview
的 image 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];
关于ios - UIAutomation中如何识别添加到UIButton的 subview (imageviews)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25301076/