nsmutableattributedstring

Append NSAttributed text to UITextview

坚强是说给别人听的谎言 提交于 2019-12-08 12:37:11
问题 I can't believe I am asking this question but (been looking for the answer for an hour and a half with no luck)... how do I append NSAttributedText to a UITextView? (in Swift 2.0+) I'm building a tool which downloads items from my server, and as they come in I want to add AttributedText with green for success or red color for fails. To do this I believe I need NSMutableAttributedString, but the UITextView only has NSattributedString which does not have access to the appendAttributedString

Highlight or Underline Specific Word in a String

ぃ、小莉子 提交于 2019-12-08 10:46:49
问题 I would like to highlight or underline a specific set of words in a NSString . I am able to detect if the words exist, I'm just not able to get them highlighted. NSString * wordString = [NSString stringWithFormat:@"%@", [self.myArray componentsJoinedByString:@"\n"]]; self.myLabel.text = wordString; if ([wordString rangeOfString:@"Base Mix"].location == NSNotFound) { NSLog(@"string does not contain base mix"); } else { NSLog(@"string contains base mix!"); NSMutableAttributedString * string = [

How to use NSSuperscriptAttributeName for OS X

人走茶凉 提交于 2019-12-08 09:31:31
问题 I can change the font and size but I'm stuck with making text a superscript. Here is my working code for font and size: aVerseMutableString = NSMutableAttributedString(string: book.verseText, attributes: [NSFontAttributeName:NSFont(name: "Helvetica", size: 18.0)!]) Here is what I'm trying for superscript that's not working: aVerseNumberMutableString = NSMutableAttributedString(string: verseNumber.description, attributes: [NSSuperscriptAttributeName:NSNumber(1)!]) I'm not sure how to do the

Swift 3.0 convert Double() to NSMutableAttributedString

余生颓废 提交于 2019-12-08 06:28:27
问题 in advance thanks for help. I am trying to make calculator application (for specific purposes) and I would like to know, if there exist a way how to convert Double() to NSMutableAttributedString. I need this for label output answer. Reason of using NSMutableAttributedString is because I would like to have answer with subscripts and upper-scripts. //example of my code var a = Double(), b = Double(), c = Double() a = Double(textField1.text!) b = Double(textField2.text!) c = a + b let font

Swift 3.0 convert Double() to NSMutableAttributedString

江枫思渺然 提交于 2019-12-06 17:47:27
in advance thanks for help. I am trying to make calculator application (for specific purposes) and I would like to know, if there exist a way how to convert Double() to NSMutableAttributedString. I need this for label output answer. Reason of using NSMutableAttributedString is because I would like to have answer with subscripts and upper-scripts. //example of my code var a = Double(), b = Double(), c = Double() a = Double(textField1.text!) b = Double(textField2.text!) c = a + b let font:UIFont? = UIFont(name: "Courier", size:12) let fontSuper:UIFont? = UIFont(name: "Courier", size:10) //for x

Replace regex matches in attributed string with image in Objective-C

旧巷老猫 提交于 2019-12-06 11:54:38
问题 My goal is to store the information for an attributed string in Parse.com. I decided to come up with an encoding for attributed text for my images that works by replacing any string {X} in braces with the corresponding image. For example: Picture of 2 colorless mana: {X} Should produce an attributed string where {X} is replaced by an image. This is what I've tried: NSString *formattedText = @"This will cost {2}{PW}{PW} to cast."; NSRegularExpression *regex = [NSRegularExpression

Change text color of WKInterfaceLabel using NSMutableAttributedString

廉价感情. 提交于 2019-12-06 06:36:30
问题 I'm trying to change text color in WKInterfaceLabel using setAttributedText property. Here's the code: MyRowController *row = [self.interfaceTable rowControllerAtIndex:idx]; NSString *str_tmp = @"Test"; NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str_tmp]; [text addAttribute:NSFontAttributeName value:[UIFont fontWithName:FONT_REGULAR size:12.0] range:NSMakeRange(0, str_tmp.length)]; [text addAttribute:NSForegroundColorAttributeName value:[UIColor

how can I change style of pre-selected words in my textView?

风流意气都作罢 提交于 2019-12-05 16:07:16
This is a follow up to this question How can I change style of some words in my UITextView one by one in Swift? Thanks to @Josh's help I was able to write a piece of code that highlights each word that begins with # - and do it one by one. My final code for that was: func highlight (to index: Int) { let regex = try? NSRegularExpression(pattern: "#(\\w+)", options: []) let matches = regex!.matches(in: hashtagExplanationTextView.text, options: [], range: NSMakeRange(0, (hashtagExplanationTextView.text.characters.count))) let titleDict: NSDictionary = [NSForegroundColorAttributeName: orangeColor]

iOS - How to use `NSMutableString` in swift

旧街凉风 提交于 2019-12-05 01:46:26
问题 I have seen this Objective-C code but I'm struggling to do the same in swift: NSMutableAttributedString *res = [self.richTextEditor.attributedText mutableCopy]; [res beginEditing]; __block BOOL found = NO; [res enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, res.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) { if (value) { UIFont *oldFont = (UIFont *)value; UIFont *newFont = [oldFont fontWithSize:oldFont.pointSize * 2]; [res removeAttribute

Replace regex matches in attributed string with image in Objective-C

a 夏天 提交于 2019-12-04 17:08:24
My goal is to store the information for an attributed string in Parse.com. I decided to come up with an encoding for attributed text for my images that works by replacing any string {X} in braces with the corresponding image. For example: Picture of 2 colorless mana: {X} Should produce an attributed string where {X} is replaced by an image. This is what I've tried: NSString *formattedText = @"This will cost {2}{PW}{PW} to cast."; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?<=\\{)[^}]+(?=\\})" options:NSRegularExpressionAnchorsMatchLines error:nil];