Objective-C:格式化 plist 中字符串对象中的文本

发布于 2024-09-08 07:09:53 字数 343 浏览 4 评论 0原文

我是一名新的 Objective-C/iPhone 开发人员,想知道是否有任何方法可以将格式应用于 plist 中字符串内的文本?

我有一个 plist,它是一组字典。每个字典都包含一些字符串对象,其中一些我想包含信息列表和段落。我正在调用这些字符串并通过 UI 中的标签显示它们。

类似于使用

  • ;和
  • 在 html 中,我希望能够指定在显示为项目符号列表、粗体、斜体等时要格式化的字符串部分。如何实现这一点?

    在该网站上一些善良用户的帮助下,我能够嵌入

  • xml plist 文件中的标签,但这只会导致在屏幕上打印标签。
  • 预先感谢您的帮助!

    I am a new objective-c/iPhone developer and am wondering if there is any way to apply formatting to text within a string in a plist?

    I have a plist that is an array of dictionaries. Each dictionary contains a few string objects, some of which I would like to contain lists and paragraphs of information. I am calling these strings and displaying them via labels in the UI.

    Similar to using <li> and </li> or <b> and </b> in html, I would like to be able to specify parts of a string to be formatted when displayed as a bulleted list, bold, italic, etc.. How could this be accomplished?

    With the help of some kind users on this site, I was able to embed the <li> and <b> tags within the xml plist file, however this just resulted in literally printing the tags on the screen.

    Thanks in advance for your help!!

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(2

    做个ˇ局外人 2024-09-15 07:09:53

    听起来您的字符串位于 plist 中这一事实与该问题没有多大关系。无论如何,您都会以这种方式存储它们。但是,如果您想在 UI 中呈现类似 HTML 的格式,您有两种选择:

    1. 将数据解析为
      NSAttributedString,即
      从 iOS 3.2 开始可用。我
      相信你必须弄清楚
      如何从 HTML 中获取
      代表权在右边
      字符串中的属性。
    2. 使用 UIWebView 并直接渲染 HTML。这听起来很重量级,尤其是对于唱片公司来说,而且可能会是这样,但你可以尝试一下。

    (这里的要点是,你的问题没有一个简单的答案——Cocoa 框架本身并不支持太多 HTML,而且字符串内格式化也不是一件容易完成的事情。)

    It doesn't sound like the fact that your strings are in a plist has much to do with the issue. You'll be storing them that way regardless. But if you want to render HTML-like formatting inside your UI, you have two choices:

    1. Parse the data into an
      NSAttributedString, which is
      available starting in iOS 3.2. I
      believe you'll have to figure out
      how to get from the HTML
      representation to the right
      attributes in the string.
    2. Use a UIWebView and render your HTML directly. This sounds heavyweight, esp for labels, and it probably would be, but you could try.

    (Gist here is that there isn't a trivial answer to your question-- the Cocoa frameworks don't natively speak much HTML, and intra-string formatting isn't something that's necessarily easily done.)

    波浪屿的海角声 2024-09-15 07:09:53

    要使 HTML 标记正常工作,您需要在 UIWebView(而不是 UILabel)中显示文本。查看 UIWebView 文档

    更新:针对其他答案,我不相信 UILabel 即使在 iOS 4 上也能正确显示 NSAttributedString。Apple 推荐的样式化文本方法是使用 UIWebView (或自己绘制文本)使用 核心文本,即明显更复杂)。

    For HTML markup to work, you'll need to display the text in a UIWebView, not a UILabel. Check out the UIWebView documentation here.

    Update: In response to the other answer, I don't believe UILabel will correctly display an NSAttributedString even on iOS 4. Apple's recommended approach to doing styled text is to use a UIWebView (or draw the text yourself using Core Text, which is significantly more complicated).

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文