English 中文(简体)
显示NSMutableAttributedString
原标题:Displaying NSMutableAttributedString

我的 app有以下代码:

NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:self.myDisplayTxt];
      [string addAttribute:(NSString*)kCTForegroundColorAttributeName 
                     value:(id)[[UIColor redColor] CGColor]
                     range:NSMakeRange(0,5)];

    self.myTextView.text = string;

在将NSMutableAttributedString派到UIText 我的看法有以下错误:

Incompatible objective c types struct NSMutableAttributedString expected struct nsstring

因此,请让我知道,我如何能够在UITextView中展示一下NStableAttributedString。

问题回答

你可以尝试利用一些图书馆这样做。 如om所写,UITextView并不不幸地支持<代码>。 NSAttributedString。

或许可以帮助你:https://github.com/enormego/EGOTextView

They say about this library the following:

UITextView替换,为国家航空航天局提供额外支助。

UPDATE: Based on your clarification in the comment for omz s answer, you can look here: Underline text inside uitextview

<><>>> 在iOS 6上,你可以将NSAttributedString从盒子中删除。 例如:

UIColor *_red=[UIColor redColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0] range:NSMakeRange(0, _stringLength)];

页: 1 如果你真的只想利用所描述的扼杀物确定地色(如你的例子),那么你可以通过确定案文观点来达到同样的目的:<条码>。

您应当通过<代码>UITextView.attributedText,对财产进行描述。 www.un.org/chinese/ga/president

textView.attributedText = attributedString;

见文件:

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextView_Class/index.html#/apple_ref/coc/stp/ITatbuted





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签