Binding to properties of WebView (Cocoa WebKit)

642 Views Asked by At

I'm storing font preferences for a WebView in my shared user defaults. I have a WebView set up in my XIB, but it isn't possible to bind a WebView's font properties in IB, so I'm wondering if I can do it in code instead. I've tried this:

WebPreferences *webPrefs = [WebPreferences standardPreferences];
[webPrefs bind:@"fixedFontFamily"
      toObject:[NSUserDefaultsController sharedUserDefaultsController]
   withKeyPath:@"values.webViewMonospaceFontFamily"
       options:nil];
[myWebView setPreferences:webPrefs];

and it doesn't work.

If this is not going to work, what would be a working strategy for changing my WebView's font when the user selects a new font in my preferences window? Do I have to manually set it in my changeFont: method?

1

There are 1 best solutions below

0
On BEST ANSWER

Update. This does work. WebPreferences has more font properties than I thought, and fixedFontFamily was the wrong one for the page I was viewing.