首页 \ 问答 \ UITextView Alternative(UITextView Alternative)

UITextView Alternative(UITextView Alternative)

正如我从Apple docs UITextView的attributesText属性中理解的那样:

默认情况下,此属性为零。 为此属性分配新值也会使用相同的字符串数据替换text属性的值,尽管没有任何格式设置信息。 此外,指定新值会更新font,textColor和textAlignment属性中的值,以便它们反映从属性字符串中的位置0开始的样式信息。

因此,我不能通过在不同位置具有多个属性的代码添加一个attributionString。

有人可以帮我用iOS6中的代码创建以下效果吗? 这可以使用nib文件和在UITextView中更改文本部分的范围属性,但我似乎无法通过代码重现效果。

<'font systemFontOfSize = 18> 所需的 <'/ font> 效果 <'textColor = [UIColor redColor]> 写入b <'/ textColor> y代码

假设标签对应于属性。

PS我不想使用CATextLayers,因为我试图使用UITextView的AutoLayout功能。


As i understood from Apple docs attributedText property of UITextView:

This property is nil by default. Assigning a new value to this property also replaces the value of the text property with the same string data, albeit without any formatting information. In addition, assigning a new a value updates the values in the font, textColor, and textAlignment properties so that they reflect the style information starting at location 0 in the attributed string.

Therefore i cannot add an attributedString by code with multiple Attributes at different locations.

Can someone please help me create the following effect by code in iOS6? This is possible using nib files and by changing range attributes for text parts in UITextView but i cant seem to reproduce the effect by code.

<'font systemFontOfSize=18>Desired<'/font> effect <'textColor = [UIColor redColor]> to be written b<'/textColor>y code.

Suppose the tags correspond to attributes.

P.S. I don't want to use CATextLayers since i am trying to use the AutoLayout feature with the UITextView.


原文:https://stackoverflow.com/questions/13932550
更新时间:2022-10-27 17:10

最满意答案

Data.Text.concat是一个O(n+m)操作,其中nm是要连接的字符串的长度。 这是因为必须分配大小为n + m的新内存缓冲区来存储连接的结果。

Builder专门针对mappend操作进行了优化。 这是一种廉价的O(1)操作(功能组合,GHC也极好地优化)。 使用Builder您实际上是在构建有关如何生成最终字符串结果的说明,但是延迟实际创建,直到您执行某些Builder -> Text转换。

要回答您的问题,如果您已经分析了应用程序并发现Text.concat在运行时占主导地位,则应选择Builder 。 这显然取决于您的需求和应用。 什么时候应该使用Builder没有通用规则,但对于简短的Text文字,可能没有必要。

如果使用Builder将涉及“进行大规模重构”,那么分析肯定是值得的。 虽然不言而喻,Haskell自然会使这种重构比你习惯使用开发人员友好的语言少得多,所以它可能并不是一项艰巨的任务。


Data.Text.concat is an O(n+m) operation where n and m are the lengths of the strings you want to concat. This is because a new memory buffer of size n + m must be allocated to store the result of the concatenation.

Builder is specifically optimized for the mappend operation. It's a cheap O(1) operation (function composition, which is also excellently optimized by GHC). With Builder you are essentially building up the instructions for how to produce the final string result, but delaying the actual creation until you do some Builder -> Text transformation.

To answer your questions, you should choose Builder if you have profiled your application and discovered that Text.concat are dominating the run time. This will obviously depend on your needs and application. There is no general rule for when you should use Builder but for short Text literals there is probably no need.

Profiling would definitely be worthwhile if using Builder would involve "undertaking a large-scale refactoring". Although it goes without saying that Haskell will naturally make this kind of refactoring much less painful than you might be used to with less developer friendly languages, so it might not be such a difficult undertaking after all.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。