@@ -11,10 +11,10 @@ @interface AccessibilityViewController_AccessibilityView : UIView
11
11
@property (nonatomic , assign ) BOOL activationReturnValue;
12
12
@property (nonatomic , assign ) int activationCount;
13
13
14
- @property (nonatomic , strong ) UILabel *label;
14
+ @property (nonatomic , strong ) UILabel *topLabel;
15
+ @property (nonatomic , strong ) UILabel *swtichLabel;
15
16
@property (nonatomic , strong ) UISwitch *activationSwitch;
16
17
17
-
18
18
@end
19
19
20
20
@@ -24,16 +24,16 @@ - (instancetype)initWithCoder:(NSCoder *)coder {
24
24
self = [super initWithCoder: coder];
25
25
self.isAccessibilityElement = YES ;
26
26
self.accessibilityLabel = @" AccessibilityView" ;
27
-
28
-
27
+
29
28
self.activationReturnValue = YES ;
30
-
31
- self.label = [[UILabel alloc ] initWithFrame: CGRectZero ];
32
- [self addSubview: self .label];
33
-
34
- self.backgroundColor = [UIColor systemTealColor ];
35
- self.label .text = @" Returns YES" ;
36
29
30
+ self.topLabel = [[UILabel alloc ] initWithFrame: CGRectZero ];
31
+ self.topLabel .text = @" Awaiting activation or tap" ;
32
+ [self addSubview: self .topLabel];
33
+
34
+ self.swtichLabel = [[UILabel alloc ] initWithFrame: CGRectZero ];
35
+ self.swtichLabel .text = @" Returns YES" ;
36
+ [self addSubview: self .swtichLabel];
37
37
38
38
self.activationSwitch = [[UISwitch alloc ] initWithFrame: CGRectZero ];
39
39
[self addSubview: self .activationSwitch];
@@ -50,35 +50,54 @@ - (void)toggleReturnValue {
50
50
51
51
if (self.activationReturnValue == YES ) {
52
52
self.backgroundColor = [UIColor systemTealColor ];
53
- self.label .text = @" Returns YES" ;
53
+ self.swtichLabel .text = @" Returns YES" ;
54
54
} else {
55
55
self.backgroundColor = [UIColor systemTealColor ];
56
- self.label .text = @" Returns NO" ;
56
+ self.swtichLabel .text = @" Returns NO" ;
57
57
}
58
58
[self setNeedsLayout ];
59
59
}
60
60
61
61
-(void )layoutSubviews {
62
62
[super layoutSubviews ];
63
- [self .label sizeToFit ];
64
- self.label .frame = CGRectMake ((self.frame .size .width - self.label .frame .size .width ) / 2 ,
65
- (self.frame .size .height - self.label .frame .size .height ) / 2 ,
66
- self.label .frame .size .width ,
67
- self.label .frame .size .height );
63
+ [self .topLabel sizeToFit ];
64
+ self.topLabel .frame = CGRectMake (20 ,
65
+ 20 ,
66
+ self.topLabel .frame .size .width ,
67
+ self.topLabel .frame .size .height );
68
+
69
+ [self .swtichLabel sizeToFit ];
70
+ self.swtichLabel .frame = CGRectMake (20 ,
71
+ CGRectGetMaxY (self.topLabel .frame ) + 40 ,
72
+ self.swtichLabel .frame .size .width ,
73
+ self.swtichLabel .frame .size .height );
68
74
69
75
[self .activationSwitch sizeToFit ];
70
- self.activationSwitch .frame = CGRectMake ((self. frame . size . width - self. activationSwitch . frame . size . width ) / 2 ,
71
- CGRectGetMaxY (self.label .frame ) + 10 ,
76
+ self.activationSwitch .frame = CGRectMake (20 ,
77
+ CGRectGetMaxY (self.swtichLabel .frame ) + 10 ,
72
78
self.activationSwitch .frame .size .width ,
73
79
self.activationSwitch .frame .size .width );
80
+
81
+ }
82
+
83
+ - (NSString *)accessibilityValue {
84
+ return self.topLabel .text ;
74
85
}
75
86
76
87
- (BOOL )accessibilityActivate {
77
88
self.activationCount += 1 ;
78
- self.accessibilityValue = [NSString stringWithFormat: @" Activated: %i " , self .activationCount];
89
+ self.topLabel .text = [NSString stringWithFormat: @" Activated: %i " , self .activationCount];
90
+ [self setNeedsLayout ];
79
91
return self.activationReturnValue ;
80
92
}
81
93
94
+
95
+ - (void )touchesEnded : (NSSet <UITouch *> *)touches withEvent : (UIEvent *)event {
96
+ CGPoint location = [[touches anyObject ] locationInView: self ];
97
+ self.topLabel .text = [NSString stringWithFormat: @" Tapped - x:%.04f , y:%.04f " , location.x, location.y];
98
+ [self setNeedsLayout ];
99
+ }
100
+
82
101
@end
83
102
84
103
@interface AccessibilityViewController : UIViewController
0 commit comments