Guest User

Untitled

a guest
Jun 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. - (NSAttributedString*)attributedName {
  2. NSMutableAttributedString* name = [[NSMutableAttributedString alloc] initWithString:self.name];
  3. [name setAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:[UIFont systemFontSize]]} range:[self.name rangeOfString:self.lastname]];
  4. return name;
  5. }
  6.  
  7. UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
  8. uint32_t existingTraitsWithNewTrait = UIFontDescriptorTraitBold;
  9. fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:existingTraitsWithNewTrait];
  10. UIFont *updatedFont = [UIFont fontWithDescriptor:fontDescriptor size:0.0];
  11. NSDictionary *attribs = @{NSFontAttributeName : updatedFont};
  12. [mutableAttrString setAttributes:attribs range:result.range];
  13.  
  14. public extension UILabel {
  15.  
  16. /// Makes the text bold.
  17. public func makeBold() {
  18. //get the UILabel's fontDescriptor
  19. let desc = self.font.fontDescriptor().fontDescriptorWithSymbolicTraits(.TraitBold)
  20. //Setting size to '0.0' will preserve the textSize
  21. self.font = UIFont(descriptor: desc, size: 0.0)
  22. }
  23.  
  24. }
  25.  
  26. let s = "(client.givenName) (client.surname)" as NSString
  27.  
  28. let myAttribute = [ NSFontAttributeName: UIFont.preferredFontForTextStyle(UIFontTextStyleTitle1) ]
  29. let myString = NSMutableAttributedString(string: "(s)", attributes: myAttribute )
  30.  
  31. let myRange = s.rangeOfString(client.surname)
  32. let desc = UIFont.preferredFontForTextStyle(UIFontTextStyleTitle1).fontDescriptor().fontDescriptorWithSymbolicTraits(.TraitBold)
  33. let new = UIFont(descriptor: desc, size: 0.0)
  34.  
  35. myString.addAttribute(NSFontAttributeName, value: new, range: myRange)
  36.  
  37. nameLabel.attributedText = myString
  38.  
  39. [name setAttributes:@{NSStrokeWidthAttributeName : @-3.0} range:NSRangeFromString(name.string)];
  40.  
  41. name.setAttributes([.strokeWidth: NSNumber(value: -3.0)], range: NSRangeFromString(name.string))
Add Comment
Please, Sign In to add comment