nsmutableattributedstring

Change the color of a link in an NSMutableAttributedString

℡╲_俬逩灬. 提交于 2019-11-30 06:24:52
问题 I have the following code but my links are always blue. How do I cange the color of them? [_string addAttribute:NSLinkAttributeName value:tag range:NSMakeRange(position, length)]; [_string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:(12.0)] range:NSMakeRange(position, length)]; [_string addAttribute:NSStrokeColorAttributeName value:[UIColor greenColor] range:NSMakeRange(position, length)]; _string is a NSMutableAttributedString and the position and

How to bold some words in my UITextView using NSMutableAttributedString?

半城伤御伤魂 提交于 2019-11-30 01:39:01
问题 I have a UITextView and there are certain words I'm casting with NSString stringWithFormat that I'd like to be bolded. I have looked around Stack Overflow and tried to follow the the postings but I guess I'm not understanding it. Here's what I've been playing around with: NSRange boldedRange = NSMakeRange(0, 4); NSString *boldFontName = [[UIFont fontWithName:@"Helvetica-Bold" size:100]fontName]; NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:self

Setting NSLinkAttributeName font color

好久不见. 提交于 2019-11-30 01:09:39
问题 I feel like I'm missing something easy but I can't seem to find out how to do this: I set the attribute to a link like so: [myAttrString addAttribute:NSLinkAttributeName value:linkURL range:selectedRange]; That works but the link is blue and I can't seem to change the color. This sets everything except the link to white: [myAttrString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:selectedRange]; Is there another color attribute name that I can't seem to find

How to change colour of the certain words in label - Swift 3 [duplicate]

喜夏-厌秋 提交于 2019-11-29 15:49:57
问题 This question already has answers here : Changing specific text's color using NSMutableAttributedString in Swift (21 answers) Closed 3 years ago . Created a Label with a simple text. How can I change the color of the certain words in the label? Swift 3 Like below- 回答1: Use NSMutableAttributedString to apply colors for different words in a string. Try this, there are already lot of similar questions have the answers in SO. let myLabel = UILabel() var stringOne = "Swift 3 has come" let

NSMutableAttributedString initWithData: causing EXC_BAD_ACCESS on rotation

本秂侑毒 提交于 2019-11-29 12:12:40
问题 I display different types of contents in a tableview and calculate the height of each cell using different custom methods, in heightForRowAtIndexPath . One of these custom methods implies converting some html in an NSMutableAttributedString , and then calculating the height of this NSMutableAttributedString . For html conversion I use the new initWithData: method. All works perfectly except when I rotate the screen => I've got an exc_bad_access every time. Using Instruments / Zombies, I've

Change the color of a link in an NSMutableAttributedString

别等时光非礼了梦想. 提交于 2019-11-28 18:06:27
I have the following code but my links are always blue. How do I cange the color of them? [_string addAttribute:NSLinkAttributeName value:tag range:NSMakeRange(position, length)]; [_string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:(12.0)] range:NSMakeRange(position, length)]; [_string addAttribute:NSStrokeColorAttributeName value:[UIColor greenColor] range:NSMakeRange(position, length)]; _string is a NSMutableAttributedString and the position and length work fine. Swift Updated for Swift 4.2 Use linkTextAttributes with a UITextView textView

Underline part of a string using NSMutableAttributedString in iOS 8 is not working

血红的双手。 提交于 2019-11-28 18:06:26
I try to underline part of a string, for example, a ' string ' part in ' test string ' string. I'm using NSMutableAttributedString and my solution was working well on iOS7 . NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"test string"]; [attributedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(5, 6)]; myLabel.attributedText = attributedString; The problem is that my solution is not working in iOS8 anymore. After spending an hour on testing multiple variants of NSMutableAttributedString , I

Displaying text in a NSScrollView (Swift)

感情迁移 提交于 2019-11-28 11:27:00
Just started to learn Swift and created a little macOS app in which I want to use a NSScrollView to display an attributed String. I’ve tried: @IBOutlet var ScrollViewOutlet : NSScrollView var attributedString = NSMutableAttributedString(string: myText) ScrollViewOutlet.insertText(attributedString) But that doesn’t seem to work. I find that a bit confusing, since doing the exact same with a NSTextView instead works like a charm. What am I missing here? In the following example, I added the scrollView in the interface builder as my starting point. The following works if you your scrollView

Highlight just the text in a UILabel

不打扰是莪最后的温柔 提交于 2019-11-27 13:19:04
I'm attempting to set the background color/highlight just the text within a UILabel . The issue is that the line breaks and spaces added to the UILabel to keep the text centered are also being highlighted. Notice the spacing before the last line in the UILabel is highlighted. Also, the beginning and end of any new lines are also highlighted. I'm creating the example above with the following code: -(void)createSomeLabel { // Create and position my label UILabel *someLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 40, self.view.frame.size.height - 300)];

NSMutableAttributedString add different alignments

社会主义新天地 提交于 2019-11-27 12:28:54
Is it possible to add left and right alignments to different parts of the string? I tried to add alignment attribute to the right part: NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init]; [paragrahStyle setAlignment:NSTextAlignmentRight]; [mutableAttributedString addAttribute:NSParagraphStyleAttributeName value:paragrahStyle range:rangeOfDate]; But the whole string is aligned to the left. What you do in your code is to set the paragraph style (the text from \n to \n) and it is not possible to have multiple text alignments in the same paragraph. I had the same