我不知道你的問題的背景(即你想做什麼),但另一種解決問題的方法可能涉及使用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];
}
}
出於好奇,爲什麼你想知道嗎? –