0

I'm exploring Apple Accessibility Audit in Xcode and can't figure out how an audit like elementDetection (XCUIAccessibilityAuditTypeElementDetection) works at all.

My goal is to build the elements so that AccessibilityAudit shows me a violation of this type (elementDetection). Please, if anyone has received such a violation, tell us how you achieved it.

Thanks.

I created a custom button that has accessibility violations. It has a UIAccessibilityCustomAction without a name, which logically should cause a violation of elementDetection. I also tried to make elements invisible with a height of 0 by 0, elements that are off screen, but they isAccessible = true.

class ProductCardView: UIButton {
    private let productImageView = UIImageView()
    private let productNameLabel = UILabel()
    private let productPriceLabel = UILabel()
    
    init() {
        super.init(frame: .zero)
        setupViews()
        setupAccessibility()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupViews() {
        productImageView.image = UIImage(named: "exampleImage")
        productNameLabel.text = "Product Name"
        productPriceLabel.text = "$99.99"
        
        addSubview(productImageView)
        addSubview(productNameLabel)
        addSubview(productPriceLabel)
        
        productImageView.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(200)
        }
        
        productNameLabel.snp.makeConstraints { make in
            make.top.equalTo(productImageView.snp.bottom).offset(8)
            make.left.right.equalToSuperview().inset(8)
        }
        
        productPriceLabel.snp.makeConstraints { make in
            make.top.equalTo(productNameLabel.snp.bottom).offset(4)
            make.left.right.bottom.equalToSuperview().inset(8)
        }
    }
    
    private func setupAccessibility() {
        isAccessibilityElement = false
        productNameLabel.isAccessibilityElement = true
        productNameLabel.accessibilityLabel = nil
        let customAction = UIAccessibilityCustomAction(name: "", target: self, selector: #selector(handleCustomAction))
        accessibilityCustomActions = [customAction]
        
    }
    @objc private func handleCustomAction() -> Bool {
        print("Custom action performed.")
        return true
    }
}

0