Created
December 6, 2013 05:03
-
-
Save tomohisa/7818840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+(NSAttributedString*)attributedStringFromString:(NSString*)string font:(UIFont*)font color:(UIColor*)color{ | |
if (string==nil || ![string isKindOfClass:[NSString class]]) { | |
return [[NSAttributedString alloc] initWithString:@"" attributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:color}]; | |
} | |
NSMutableAttributedString * attrib = [[NSMutableAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:color}]; | |
NSArray * array = [TwitterText entitiesInText:attrib.string]; | |
[array enumerateObjectsUsingBlock:^(TwitterTextEntity * obj, NSUInteger idx, BOOL *stop) { | |
if (obj.type==TwitterTextEntityURL) { | |
NSURL * url = [NSURL URLWithString:[string substringWithRange:obj.range]]; | |
if (url) { | |
[attrib addAttribute:NSLinkAttributeName value:url range:obj.range]; | |
} | |
} | |
}]; | |
return attrib; | |
} | |
-(void) settingText{ | |
self.textViewlDescription.attributedText = [NSString attributedStringFromString:self.tweet.user.description font:self.textViewlDescription.font color:self.textViewlDescription.textColor]; | |
self.textViewlDescription.linkTextAttributes = @{NSForegroundColorAttributeName: TOVConstLinkColor}; | |
} | |
-(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{ | |
LOG_S(URL.description); | |
if (URL.absoluteString.length && [[URL.absoluteString substringToIndex:1] isEqualToString:@"@"]) { | |
//... @user の処理 | |
return NO; | |
} | |
NSString *decoded = (NSString *)CFBridgingRelease(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,(CFStringRef)URL.absoluteString,CFSTR(""),kCFStringEncodingUTF8)); | |
LOG(@"decodedString %@", decoded); | |
if ([URL.absoluteString containsString:@"hash://"]) { | |
//... ハッシュタグ の処理 | |
return NO; | |
} | |
//URLを内部webviewで開く | |
[self setWebHidden:NO URL:URL]; | |
return NO; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment