Skip to content

Commit b374fb8

Browse files
committed
AccessibilityUIExamples: Version 3.0, 2017-09-12
Rewritten in Swift 4. This sample contains examples of several common control elements with various implementations and code to make them accessible, including using the accessibility methods of NSControl subclasses and implementing accessibility protocols for custom elements. Signed-off-by: Liu Lantao <[email protected]>
1 parent 9ee7278 commit b374fb8

File tree

144 files changed

+10654
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+10654
-0
lines changed

AccessibilityUIExamples/.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# See LICENSE folder for this sample’s licensing information.
2+
#
3+
# Apple sample code gitignore configuration.
4+
5+
# Finder
6+
.DS_Store
7+
8+
# Xcode - User files
9+
xcuserdata/
10+
*.xcworkspace
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<array/>
5+
</plist>

AccessibilityUIExamples/AccessibilityUIExamples.xcodeproj/project.pbxproj

+1,204
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
See LICENSE folder for this sample’s licensing information.
3+
4+
Abstract:
5+
This sample's application delegate.
6+
*/
7+
8+
import Cocoa
9+
10+
@NSApplicationMain
11+
class AppDelegate: NSObject, NSApplicationDelegate {
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
See LICENSE folder for this sample’s licensing information.
3+
4+
Abstract:
5+
Helpful extension to Character.
6+
*/
7+
8+
import Cocoa
9+
10+
extension Character {
11+
init?(_ ascii: Int) {
12+
guard let scalar = UnicodeScalar(ascii) else {
13+
return nil
14+
}
15+
self = Character(scalar)
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
See LICENSE folder for this sample’s licensing information.
3+
4+
Abstract:
5+
Encompassing view that holds the detail view controller's content.
6+
*/
7+
8+
import Cocoa
9+
10+
class DetailView: NSView {
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
See LICENSE folder for this sample’s licensing information.
3+
4+
Abstract:
5+
This sample's detail view controller showing the accessibility examples.
6+
*/
7+
8+
import Cocoa
9+
import MediaLibrary
10+
11+
class DetailViewController: NSViewController {
12+
13+
@IBOutlet var descriptionField: NSTextField!
14+
@IBOutlet var exampleArea: NSView!
15+
16+
var detailItemRecord: Example! {
17+
didSet {
18+
// Remove the old child view controller, if any exists.
19+
if !childViewControllers.isEmpty {
20+
let vc = childViewControllers[0]
21+
vc.view.isHidden = true
22+
vc.removeFromParentViewController()
23+
}
24+
25+
descriptionField.stringValue = ""
26+
27+
guard detailItemRecord != nil else { return }
28+
29+
// Update the description of the example.
30+
descriptionField.stringValue = detailItemRecord.desc
31+
32+
// Check if this sample actually has a valid view controller to display.
33+
guard !detailItemRecord.viewControllerIdentifier.characters.isEmpty else { return }
34+
35+
// Load the example storyboard and embed.
36+
let storyboard: NSStoryboard =
37+
NSStoryboard(name: NSStoryboard.Name(rawValue: detailItemRecord.viewControllerIdentifier), bundle: nil)
38+
39+
let sceneIdentifier = NSStoryboard.SceneIdentifier(rawValue: detailItemRecord.viewControllerIdentifier)
40+
41+
guard let buttonViewController =
42+
storyboard.instantiateController(withIdentifier: sceneIdentifier) as? NSViewController else { return }
43+
44+
insertChildViewController(buttonViewController, at: 0)
45+
46+
buttonViewController.view.translatesAutoresizingMaskIntoConstraints = false
47+
48+
view.addSubview(buttonViewController.view)
49+
50+
// Add the proper constraints to the detail view controller so it embeds properly with it's parent view controller.
51+
let top = NSLayoutConstraint(item: buttonViewController.view,
52+
attribute: .top,
53+
relatedBy: .equal,
54+
toItem: exampleArea,
55+
attribute: .top,
56+
multiplier: 1,
57+
constant: 0)
58+
let left = NSLayoutConstraint(item: buttonViewController.view,
59+
attribute: .left,
60+
relatedBy: .equal,
61+
toItem: exampleArea,
62+
attribute: .left,
63+
multiplier: 1,
64+
constant: 0)
65+
let height = NSLayoutConstraint(item: buttonViewController.view,
66+
attribute: .height,
67+
relatedBy: .equal,
68+
toItem: exampleArea,
69+
attribute: .height,
70+
multiplier: 1,
71+
constant: 0)
72+
let width = NSLayoutConstraint(item: buttonViewController.view,
73+
attribute: .width,
74+
relatedBy: .equal,
75+
toItem: exampleArea,
76+
attribute: .width,
77+
multiplier: 1,
78+
constant: 0)
79+
view.addConstraints([top, left, height, width])
80+
}
81+
}
82+
83+
}
84+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
See LICENSE folder for this sample’s licensing information.
3+
4+
Abstract:
5+
Object to describe an accessibility example.
6+
*/
7+
8+
import Foundation
9+
10+
class Example: NSObject {
11+
var name = ""
12+
var desc = ""
13+
var viewControllerIdentifier = ""
14+
15+
init(name: String, description: String, viewControllerIdentifier: String) {
16+
self.name = name
17+
self.desc = description
18+
self.viewControllerIdentifier = viewControllerIdentifier
19+
super.init()
20+
}
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
See LICENSE folder for this sample’s licensing information.
3+
4+
Abstract:
5+
Encompassing view that holds the master view controller's content.
6+
*/
7+
8+
import Cocoa
9+
10+
class MasterView: NSView {
11+
12+
}

0 commit comments

Comments
 (0)