Created
October 31, 2011 04:15
-
-
Save mtsd/1326900 to your computer and use it in GitHub Desktop.
TableViewCellにYouTube動画を表示
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=212"/> | |
| <style type="text/css"> | |
| body { | |
| background-color: transparent; | |
| color: white; | |
| } | |
| </style> | |
| </head> | |
| <body style="margin:0"> | |
| <div> | |
| <object width="$width$" height="$height$"> | |
| <param name="movie" value="http://www.youtube.com/v/$movieId$"></param> | |
| <param name="wmode" value="transparent"></param> | |
| <embed src="http://www.youtube.com/v/$movieId$" type="application/x-shockwave-flash" wmode="transparent" width="$width$" height="$height$"></embed> | |
| </object> | |
| </div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| @interface YouTubeCell : UITableViewCell { | |
| // YouTube | |
| UIWebView* youTubeView_; | |
| NSString* youTubeHTML_; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "YouTubeCell.h" | |
| #define zYouTubeFrameSize CGSizeMake(212, 172) | |
| @interface YouTubeCell (PrivateMethods) | |
| - (void)loadYouTubeHTML; | |
| - (void)embedYouTube:(NSString*)movieId size:(CGSize)size; | |
| @end | |
| @implementation PQActivityListItemCell | |
| - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier | |
| { | |
| if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { | |
| youTubeView_ = [[UIWebView alloc] initWithFrame:CGRectZero]; | |
| [self.contentView addSubview:youTubeView_]; | |
| [self loadYouTubeHTML]; | |
| } | |
| return self; | |
| } | |
| - (void)dealloc | |
| { | |
| // YouTube | |
| [youTubeView_ release], youTubeView_ = nil; | |
| [youTubeHTML_ release], youTubeHTML_ = nil; | |
| [super dealloc]; | |
| } | |
| - (void)layoutSubviews | |
| { | |
| [super layoutSubviews]; | |
| [self layoutYouTubeView]; | |
| } | |
| - (void)layoutYouTubeView | |
| { | |
| youTubeView_.origin = CGPointMake((self.view.width - youTubeView_.width) / 2, 0); | |
| movieId = @"ApnZTL-AspQ"; | |
| [self embedYouTube:movieId size:zYouTubeFrameSize]; | |
| } | |
| #pragma mark - Private methods | |
| - (void)embedYouTube:(NSString*)movieId size:(CGSize)size | |
| { | |
| if ( movieId && ( [movieId length] > 0 ) ) { | |
| NSString* html = [youTubeHTML_ stringByReplacingOccurrencesOfString:@"$movieId$" withString:movieId]; | |
| html = [html stringByReplacingOccurrencesOfString:@"$width$" withString:[NSString stringWithFormat:@"%d", (int)size.width]]; | |
| html = [html stringByReplacingOccurrencesOfString:@"$height$" withString:[NSString stringWithFormat:@"%d", (int)size.height]]; | |
| [youTubeView_ loadHTMLString:html baseURL:nil]; | |
| } else { | |
| [youTubeView_ loadHTMLString:nil baseURL:nil]; | |
| } | |
| youTubeView_.size = size; | |
| } | |
| - (void)loadYouTubeHTML | |
| { | |
| NSString *youtubePath = [[NSBundle mainBundle] pathForResource:@"youtube" ofType:@"html"]; | |
| youTubeHTML_ = [[NSString stringWithContentsOfFile:youtubePath encoding:NSUTF8StringEncoding error:nil] retain]; | |
| } | |
| @end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
抜粋したため、動作未確認