在UIView中将字符串的部分设置为粗体 [英] Setting parts of a String to Bold in UIView

查看:164
本文介绍了在UIView中将字符串的部分设置为粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我解析一个XML文件,得到一个字符串 NSMutableString
现在我想在 UIView 中将此字符串显示为文本。
所以,我创建了一个 TextView 并将其值设置为我的字符串。结果是我有Text标签中显示的HTML标签的文本。



从字符串中删除标签没有问题,但有些文本需要



是否有任何方法可以以编程方式显示字符串的某些部分?

< br> 元素与 \\\
,它适用于换行符。



但是我仍然不知道我可以做什么,在 UIView 中的粗标签之间显示字词。

解决方案

有两种方法。第一种是通过在UIWebViews中显示它们;在iOS 4.1之前这是有效的唯一方法。



如果您确定您的应用程式只能在iOS 4.1以上运行,您可以使用Core



Apple提供了一些很好的格式资源:



关于iOS中的文字,网络和编辑支持



核心文字编程指南



WWDC 2010会话视频 - 关注链接到iTunes和抓取会话110:iPhone操作系统的高级文本处理

(需要Apple开发人员登录)


I'm parsing an XML file an get a string as NSMutableString. Now I want to show this string as text in my UIView. So, I created a TextView and set its value to my string. The result was that I have the text with HTML Tags shown up in the TextView.

There is no problem removing the tags from the string, but some of the text needs to appear as bold.

Is there any way to display parts of a string as bold programmatically?

I replaced <br> Elements with \n and it works fine for line-break.

But I still don't know what I can do to display words between strong tags as bold in the UIView.

解决方案

There are two ways. The first is by displaying them in UIWebViews; prior to iOS 4.1 this was effectively the only way. Because you already have HTML codes in the text, it would certainly be easy.

If you're ok with your app running only on iOS 4.1 and up you can use Core Text, which provides very rich formatting.

EDIT

Apple provides some good resources:

About Text, Web, and Editing Support in iOS

Core Text Programming Guide

WWDC 2010 Session Videos -- follow the link to iTunes and grab session 110: Advanced Text Handling for iPhone OS
(Apple Developer login required)

这篇关于在UIView中将字符串的部分设置为粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆