开发者

How can I determine the positioning of UIWebView from IB when it has been initialized in code?

开发者 https://www.devze.com 2023-03-09 14:41 出处:网络
I have successfully embedded a vimeo video using a UIWebView. However because i have created this in code, i have to adjust the positioning in code and i would prefer to do it through interface builde

I have successfully embedded a vimeo video using a UIWebView. However because i have created this in code, i have to adjust the positioning in code and i would prefer to do it through interface builder. Correct me if im wrong, i read that initializing UIWebView with the initWithCoder method was the way to achieve this. However i am not to sure how to properly make use of this method, if it is at all the right one.

Here is a bit code to show what i have been doing so far:

- (void) viewDidLoad{
[super viewDidLoad];
[self embedVimeo:@"http://player.vimeo.com/video/19969613" frame:CGRectMake(300, 100, 260, 200)];
[self embedVimeo:@"http://player.vimeo.com/video/19967404" frame:CGRectMake(100, 300, 260, 200)];}


- (void)embedVimeo:(NSString *)urlString frame:(CGRect)frame {
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<iframe src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></iframe>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
/*UIWebView **/ videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:html baseURL:nil];

[[[videoView subviews] lastObject] setScrollEnabled:NO];
[mai开发者_如何学GonView addSubview:videoView];
[videoView release];

}

Any ideas?

Tod


It is my understanding that the initWithCoder is automatically used by the Objective-C runtime/Cocoa/CocoaTouch to accomplish what you are aiming at. So you don't have to really worry about it.

In short, if you create you UI in IB, say instantiate there a UIWebView object, define its connection a controller of yours, then you will be able to use that UIWebView directly without worrying about having to instantiate it.

What I would do is:

  1. creating a new Web View in my nib;

  2. a controller/delegate for the WebView;

  3. connect the WebView delegate to the controller/delegate;

  4. connect the controller/delegate view to the WebView;

  5. connect the rootViewController of the main window to the controller/delegate.

Once you make sure you have defined correctly all the outlets and connection, my simply loading this nib (which in case it is the MainMenu is done automatically), you'll have all of those objects instantiated and ready to be used (by calling loadHTMLString: or whatever.

Hope this helps.

0

精彩评论

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