提交 660b1d64 编写于 作者: J John Hampton

Adds accessibility

上级 2c2455b2
......@@ -18,8 +18,8 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" axis="vertical" alignment="top" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="l36-fK-dfQ">
<rect key="frame" x="0.0" y="40" width="375" height="532.5"/>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="l36-fK-dfQ">
<rect key="frame" x="0.0" y="40" width="375" height="476.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Meal Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="n9u-9b-TSl">
<rect key="frame" x="0.0" y="0.0" width="86.5" height="20.5"/>
......@@ -50,8 +50,8 @@
<outletCollection property="gestureRecognizers" destination="UAM-fK-D64" appends="YES" id="uEG-WL-m3E"/>
</connections>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="5FE-RR-A0X" customClass="RatingControl" customModule="iOSTemplate" customModuleProvider="target">
<rect key="frame" x="0.0" y="432.5" width="50" height="100"/>
<stackView opaque="NO" contentMode="scaleToFill" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="5FE-RR-A0X" customClass="RatingControl" customModule="iOSTemplate" customModuleProvider="target">
<rect key="frame" x="0.0" y="432.5" width="252" height="44"/>
</stackView>
</subviews>
<constraints>
......
......@@ -73,7 +73,7 @@ import UIKit
let emptyStar = UIImage(named:"emptyStar", in: bundle, compatibleWith: self.traitCollection)
let highlightedStar = UIImage(named:"highlightedStar", in: bundle, compatibleWith: self.traitCollection)
for _ in 0..<starCount {
for index in 0..<starCount {
// Create the button
let button = UIButton()
......@@ -88,6 +88,9 @@ import UIKit
button.heightAnchor.constraint(equalToConstant: starSize.height).isActive = true
button.widthAnchor.constraint(equalToConstant: starSize.width).isActive = true
// Set the accessibility label
button.accessibilityLabel = "Set \(index + 1) star rating"
// Setup the button action
button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped(button:)), for: .touchUpInside)
......@@ -105,6 +108,29 @@ import UIKit
for (index, button) in ratingButtons.enumerated() {
// If the index of a button is less than the rating, that button should be selected.
button.isSelected = index < rating
// Set the hint string for the currently selected star
let hintString: String?
if rating == index + 1 {
hintString = "Tap to reset the rating to zero."
} else {
hintString = nil
}
// Calculate the value string
let valueString: String
switch (rating) {
case 0:
valueString = "No rating set."
case 1:
valueString = "1 star set."
default:
valueString = "\(rating) stars set."
}
// Assign the hint string and value string
button.accessibilityHint = hintString
button.accessibilityValue = valueString
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册