我不知道你的问题的背景(即你想做什么),但另一种解决问题的方法可能涉及使用Key Value Observing观察文本视图背景颜色的变化,并据此采取行动。
Here's some documentation让你开始使用KVO。
在代码:
static void * kBackgroundColorCtx = &kBackgroundColorCtx;
[self.myTextView addObserver:self
forKeyPath:@"backgroundColor"
options:NSKeyValueObservingOptionOld
context:kBackgroundColorCtx];
然后,在您的视图控制器实现此:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == kBackgroundColorCtx) {
NSLog(@"Background color changed from %@ to %@",
[change objectForKey:NSKeyValueChangeOldKey],
self.myTextView.backgroundColor);
} else {
// Not interested in this, pass to superclass
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
出于好奇,为什么你想知道吗? –