User stylesheets should work just fine, so you should try to figure out what's going wrong with that. Perhaps don't use standardPreferences; use [self.webView setPreferencesIdentifier:@"mySpecialPreferences"] to generate a new preferences object for your WebView, then [self.webView preferences] to get a preferences object to customize.
If that still doesn't work, why don't you just hide your WebView and show a spinner while it's loading, and then after it loads and you've injected your stylesheets, show it? -Matt On Aug 18, 2012, at 11:29 AM, Koen van der Drift <koenvanderdr...@gmail.com> wrote: > > On Aug 18, 2012, at 1:40 PM, Kyle Sluder <k...@ksluder.com> wrote: > >> This is a good start. I believe "user stylesheet" is the term of art for a >> local override stylesheet. From a quick Google, the relevant APIs are on the >> WebPreferences class: -setUserStyleSheetEnabled: and >> -setUserStyleSheetLocation:. You could start with one of the common "reset" >> stylesheets and customize it from there. > > > I tried that, but the settings in my css file are not used. > > WebPreferences *prefs = [WebPreferences standardPreferences]; > [prefs setJavaScriptEnabled: YES]; > [prefs setCacheModel: WebCacheModelDocumentBrowser]; > [prefs setPlugInsEnabled: YES]; > > NSString *path = [[NSBundle mainBundle] pathForResource: @"default" > ofType: @"css"]; > NSURL *css = [NSURL URLWithString: path]; > > [prefs setUserStyleSheetEnabled: YES]; > [prefs setUserStyleSheetLocation: css]; > > [self.webView setPreferences: prefs]; > > > > So I am now hacking in the DOM, and this way I can add my stylesheet: > > NSError *error = nil; > > DOMDocument* domDocument = [webView mainFrameDocument]; > DOMElement* styleElement = [domDocument createElement: @"style"]; > [styleElement setAttribute: @"type" value: @"text/css"]; > > NSString *path = [[NSBundle mainBundle] pathForResource: @"default" > ofType: @"css"]; > NSString *css = [NSString stringWithContentsOfFile: path encoding: > NSUTF8StringEncoding error: &error]; > > DOMText *cssText = [domDocument createTextNode: css]; > [styleElement appendChild: cssText]; > > DOMElement* headElement= (DOMElement*)[[domDocument > getElementsByTagName: @"head"] item:0]; > [headElement appendChild:styleElement]; > > > This way the css gets inserted into the DOM, but I still have the delay. > > > I am open for any suggestions/improvements :) > > - Koen. > > > > > > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/matt%40mattpatenaude.com > > This email sent to m...@mattpatenaude.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com