Skip to content

Instantly share code, notes, and snippets.

@petrpavlik
Created January 28, 2020 20:39
Show Gist options
  • Save petrpavlik/384e8cf37ebdde78e30ba4a2bcad447d to your computer and use it in GitHub Desktop.
Save petrpavlik/384e8cf37ebdde78e30ba4a2bcad447d to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// AccessibilityTest
//
// Created by Petr Pavlik on 28/01/2020.
// Copyright © 2020 Petr Pavlik. All rights reserved.
//
import UIKit
class TitleView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
let button = UIButton(type: .system)
button.setTitle("Aaaa", for: .normal)
let button2 = UIButton(type: .system)
button2.setTitle("Bbbb", for: .normal)
let stackView = UIStackView(arrangedSubviews: [button, button2])
stackView.translatesAutoresizingMaskIntoConstraints = false
addSubview(stackView)
stackView.topAnchor.constraint(equalTo: topAnchor).isActive = true
stackView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
stackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
stackView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// Voice over ands up reading the title instead of TitleView's content
// Setting title to nil fixes this.
navigationItem.titleView = TitleView()
navigationItem.title = "This should not be read by voice over"
}
}
@petrpavlik
Copy link
Author

Screenshot 2020-01-28 at 21 29 59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment