如何在 Apple TV 的 tvos 应用程序中编写 HTML iframe
How to write HTML iframe in tvos app for Apple TV
我想知道如何从本质上将某种 iframe 中的网页包装到 Apple TV 的 tvos 应用程序中。我能够使用 UITextView 写出基本 HTML 以在 tvos 应用程序中显示 - 基本 div 具有基本样式 - 但是,我无法弄清楚如何写出 iframe。
下面使用 XCode 在 Objective C 中编写的代码将在 Apple TV 模拟器中显示 "hello!!!!",但不会显示 iframe。
下面是我的代码。有什么帮助吗?谢谢!
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(IBAction)print:(id)sender{
}
- (void)viewDidLoad {
[super viewDidLoad];
CGRect textViewFrame = CGRectMake(20.0f, 20.0f, 280.0f, 124.0f);
UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame];
textView.returnKeyType = UIReturnKeyDone;
[self.view addSubview:textView];
NSString* staticHTMLContent = @"<div>hello!!!!</div> <iframe frameborder=""1"" width=""420"" height=""345"" src=""//www.youtube.com/embed/C8kSrkz8Hz8""></iframe>";
NSAttributedString* myHTMLString = [[NSAttributedString alloc] initWithData:[staticHTMLContent dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType} documentAttributes:nil error:nil];
[textView setAttributedText:myHTMLString];
}
@end
UITextView 不会加载 iframe。您需要 UIWebView 来执行此操作,但 API 在 TvOS 中不可用。
HTML 出现在您的示例中的原因是因为您可以在 UITextView 中渲染 HTML/CSS,但实际上并没有像在UIWebView,它只是用于设置内容样式以替代属性文本。
我想知道如何从本质上将某种 iframe 中的网页包装到 Apple TV 的 tvos 应用程序中。我能够使用 UITextView 写出基本 HTML 以在 tvos 应用程序中显示 - 基本 div 具有基本样式 - 但是,我无法弄清楚如何写出 iframe。
下面使用 XCode 在 Objective C 中编写的代码将在 Apple TV 模拟器中显示 "hello!!!!",但不会显示 iframe。
下面是我的代码。有什么帮助吗?谢谢!
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(IBAction)print:(id)sender{
}
- (void)viewDidLoad {
[super viewDidLoad];
CGRect textViewFrame = CGRectMake(20.0f, 20.0f, 280.0f, 124.0f);
UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame];
textView.returnKeyType = UIReturnKeyDone;
[self.view addSubview:textView];
NSString* staticHTMLContent = @"<div>hello!!!!</div> <iframe frameborder=""1"" width=""420"" height=""345"" src=""//www.youtube.com/embed/C8kSrkz8Hz8""></iframe>";
NSAttributedString* myHTMLString = [[NSAttributedString alloc] initWithData:[staticHTMLContent dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType} documentAttributes:nil error:nil];
[textView setAttributedText:myHTMLString];
}
@end
UITextView 不会加载 iframe。您需要 UIWebView 来执行此操作,但 API 在 TvOS 中不可用。
HTML 出现在您的示例中的原因是因为您可以在 UITextView 中渲染 HTML/CSS,但实际上并没有像在UIWebView,它只是用于设置内容样式以替代属性文本。