[iOS]如何给Label或者TextView赋HTML数据
//
// ViewController.m
// text
//
// Created by 李东旭 on 16/1/22.
// Copyright © 2016年 李东旭. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // 创建textView
UITextView *textV = [[UITextView alloc] initWithFrame:CGRectMake(, , self.view.frame.size.width, )];
[self.view addSubview:textV]; // 设置textView边框宽度和颜色
textV.layer.borderWidth = 2.0f;
textV.layer.borderColor = [UIColor blackColor].CGColor; // 获取html数据
NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some<em>text</em></p><img src='http://blogs.babble.com/famecrawler/files/2010/11/mickey_mouse-1097.jpg'width=70 height=100 />"; // 利用可变属性字符串来接收html数据
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil]; // 给textView赋值的时候就得用attributedText来赋了
textV.attributedText = attributedString; } @end
[iOS]如何给Label或者TextView赋HTML数据的更多相关文章
- IOS 开发之-- textfield和textview,return键的改变,点击return键
IOS 开发之-- textfield和textview,return键的改变,点击return键 一,textfield的return键改变 方案1.改变键盘右下角的换行(enter)键为完成键,后 ...
- iOS测试中发现一个textview控制,使用clear()无法清除文字
iOS测试中发现一个textview控制,使用clear()无法清除
- iOS开发中视图控制器ViewControllers之间的数据传递
iOS开发中视图控制器ViewControllers之间的数据传递 这里我们用一个demo来说明ios是如何在视图控制器之间传递重要的参数的.本文先从手写UI来讨论,在下一篇文章中讨论在storybo ...
- iOS开发之Socket通信实战--Request请求数据包编码模块
实际上在iOS很多应用开发中,大部分用的网络通信都是http/https协议,除非有特殊的需求会用到Socket网络协议进行网络数 据传输,这时候在iOS客户端就需要很好的第三方CocoaAsyncS ...
- iOS key value coding kvc在接收json数据与 model封装中的使用
iOS key value coding kvc在接收json数据与 model封装中的使用 使用 kvc 能够极大的简化代码工作,及以后的接口维护工作: 1:先创建MovieModel类.h和 . ...
- 为label或者textView添加placeHolder
Tip:使用textView的代理需要在头文件中加入: <UITextViewDelegate> h文件 @interface FeedbackViewController : UIVie ...
- iOS开发实现Label中多颜色多字体
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 100, 300, 30)]; label.textColor = wor ...
- iOS 依据文本内容为TextView动态定义高度
解决方式: 1.定义一个textview,在storyboard中设定该textview的constraints. 2.将高度的constraint定义到头文件里:(直接拖拽) @property ( ...
- iOS 如何在Label中显示html的文本
if (self.messageModel) { NSString * htmlString = self.messageModel.contentText; NSAttributedString * ...
随机推荐
- 关于华为C8812救砖教程
问题:华为C8812刷机后,开机显示:---------------------------------------------------------------- Image signature ...
- How to using x++ creating Vendors [AX2012]
.//Create party for the vendor public void createParty(VendorRequestCreate _vendorRequestCreate) { ; ...
- Json(2)-DataContractJsonSerializer
public static void DataContractSerializeDemo() { User user = new User { UserID = 1 ...
- python学习第四天第一部分
1.字典的特性:无序.去重.查询速度快.比list占用内存多. 2.字典查询速度快的原因:因为他是哈希类型的. 3.什么是(hash)哈希? hash把任意长度的二进制映射为较短的固定长度的二进制,这 ...
- ASP.NET MVC +EasyUI 权限设计(一)开篇
在前一段时间中,老魏的确非常的忙碌,Blog基本上没有更新了,非常的抱歉,那么在后面的时间中,老魏会尽量的抽时间来写的,可能时间上就不太富裕了.今天开始呢,老魏会和大家分享一下关于权限设计的有关文章, ...
- LintCode-Hash Function
In data structure Hash, hash function is used to convert a string(or any other type) into an integer ...
- Week1 Team Homework #1: Study the projects done by previous student groups
我们研究了学长的项目:百度3D地图API的调用.下面是我们对该项目的一些看法: 优点: 界面清晰 各类之间调用及其他关系容易理清. 缺点: 前段html代码过于冗杂,很多(div)块间的层次关系不 ...
- 3044 矩形面积求并 - Wikioi
题目描述 Description 输入n个矩形,求他们总共占地面积(也就是求一下面积的并) 输入描述 Input Description 可能有多组数据,读到n=0为止(不超过15组) 每组数据第一行 ...
- 1072: [SCOI2007]排列perm - BZOJ
Description 给一个数字串s和正整数d, 统计s有多少种不同的排列能被d整除(可以有前导0).例如123434有90种排列能被2整除,其中末位为2的有30种,末位为4的有60种.Input ...
- c++ 信号量
最近写了个c++项目,发现 ctrl + c 退出程序可以出发析构,但kill pid,则不会触发析构,导致现场数据丢失. 解决方案:同时捕捉以下信号. signal(SIGINT, &完成命 ...