UITextView加载网页内容:

@interface ViewController ()

@property (nonatomic, strong) UITextView *tvContent;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.tvContent = [[UITextView alloc] init];
    self.tvContent.editable = NO;
    self.tvContent.backgroundColor = [UIColor greenColor];
    self.tvContent.textContainer.lineFragmentPadding = 0.0;
    self.tvContent.textContainerInset = UIEdgeInsetsZero;
    [self.view addSubview:self.tvContent];
    
    NSString *strA = @"<font color=\"#6c6c6c\">满20减5 满40减15,还剩<font color=\"#ff9147\">113天<a href=\"tel://17682304296\">打电话</a>akjfks<a href=\"http://www.baidu.com\">百度</a>是开发接口数据反馈ksjdf会计师考虑快乐圣诞节疯狂了技术科就开始第六节疯狂姜看到了设计费收费就空数据反馈<br><img src=\"https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2892970100,3188725314&fm=200&gp=0.jpg\"></img>";
    NSDictionary *dic = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType
                          };
    NSMutableAttributedString *mAStr = [[NSMutableAttributedString alloc] initWithData:[strA dataUsingEncoding:NSUnicodeStringEncoding] options:dic documentAttributes:nil error:nil];
    
    self.tvContent.attributedText = mAStr;
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    
    CGFloat height = [self.tvContent sizeThatFits:CGSizeMake([self maxWidth], MAXFLOAT)].height;
    
    self.tvContent.frame = CGRectMake(15.0, 100, [self maxWidth], height);
}

- (CGFloat)maxWidth {
    return self.view.bounds.size.width - 15.0 * 2;
}

@end

效果:

UITextView加载网页内容:
效果示例

相关文章:

  • 2022-01-23
  • 2021-08-08
  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-04
  • 2022-12-23
  • 2021-12-23
  • 2021-08-05
  • 2021-09-27
  • 2021-05-25
  • 2022-12-23
相关资源
相似解决方案