Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (TTTAttributedLabel *)createAutoLayoutAttributedLabelWithFont:(UIFont *)font andColor:(UIColor *)color {
  2.     TTTAttributedLabel *label = [[TTTAttributedLabel alloc] init];
  3.     label.numberOfLines = 0;
  4.     label.lineBreakMode = NSLineBreakByWordWrapping;
  5.     label.translatesAutoresizingMaskIntoConstraints = NO;
  6.     [label setPreferredMaxLayoutWidth:kPreferredMaxLayoutWidth];
  7.     label.font = font;
  8.     label.textColor =  color;
  9.     label.enabledTextCheckingTypes = NSTextCheckingAllTypes;
  10.    
  11.     if ([UIDevice canMakeCalls]) {
  12.         NSArray *linkAttributesKeys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,(id)kCTUnderlineStyleAttributeName, nil];
  13.         NSArray *linkAttributesObjects = [[NSArray alloc] initWithObjects:[UIColor oceanBlueColor],[NSNumber numberWithInt:kCTUnderlineStyleNone],nil];
  14.         label.linkAttributes = [[NSDictionary alloc] initWithObjects:linkAttributesObjects forKeys:linkAttributesKeys];
  15.        
  16.         NSArray *activeAttributesKeys1 = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,(id)kCTUnderlineStyleAttributeName, nil];
  17.         NSArray *activeAttributesobjects = [[NSArray alloc] initWithObjects:[[UIColor oceanBlueColor] colorWithAlphaComponent:0.25f],[NSNumber numberWithInt:kCTUnderlineStyleNone],nil];
  18.         label.activeLinkAttributes = [[NSDictionary alloc] initWithObjects:activeAttributesobjects forKeys:activeAttributesKeys1];
  19.     } else {
  20.         NSArray *keys = [[NSArray alloc] initWithObjects:(id)kCTForegroundColorAttributeName,(id)kCTUnderlineStyleAttributeName,(id)kCTFontAttributeName, nil];
  21.         NSArray *objects = [[NSArray alloc] initWithObjects:color,[NSNumber numberWithInt:kCTUnderlineStyleNone],[UIFont fontWithName:kFontName size:font.pointSize] ,nil];
  22.         label.linkAttributes = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];
  23.         label.activeLinkAttributes = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];
  24.     }
  25.     label.delegate = self;
  26.    
  27.     return label;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement