开发者

Binding to properties of WebView (Cocoa WebKit)

开发者 https://www.devze.com 2023-02-08 04:15 出处:网络
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

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"
 开发者_如何学Go      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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消