title: Highlight just the text in a UILabel
body: <p>I'm attempting to set the background color/highlight just the text within a <code>UILabel</code>. The issue is that the line breaks and spaces added to the <code>UILabel</code> to keep the text centered are also being highlighted.</p>
  
  <p><img src="https://i.stack.imgur.com/UDr6E.png" alt="enter image description here"></p>
  
  <p>Notice the spacing before the last line in the <code>UILabel</code> is highlighted. Also, the beginning and end of any new lines are also highlighted.</p>
  
  <p>I'm creating the example above with the following code:</p>
  
  <pre><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)];
      someLabel.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2);
      someLabel.textAlignment = NSTextAlignmentCenter;
      someLabel.textColor = [UIColor whiteColor];
      someLabel.lineBreakMode = NSLineBreakByWordWrapping;
      someLabel.numberOfLines = 0;
      [self.view addSubview:someLabel];
  
      // This string will be different lengths all the time
      NSString *someLongString = @"Here is a really long amount of text that is going to wordwrap/line break and I don't want to highlight the spacing. I want to just highlight the words and a single space before/after the word";
  
      // Create attributed string
      NSMutableAttributedString *someLongStringAttr=[[NSMutableAttributedString alloc] initWithString:someLongString attributes:nil];
  
      // Apply background color
      [someLongStringAttr addAttribute:NSBackgroundColorAttributeName
                        value:[UIColor colorWithWhite:0 alpha:0.25]
                        range:NSMakeRange(0, someLongStringAttr.length)];
  
      // Set text of label
      someLabel.attributedText = someLongStringAttr;
  }
  </code></pre>
  
  <p><strong>The output I'd like to achieve</strong> is to highlight only the text and the spaces between the words if there is only one space. The length of the text and the size of the <code>UILabel</code> will constantly be different so hard coding a solution is not an option unfortunately.</p>