希望下面的代碼片段可能會爲你工作
-(NSAttributedString*)configureToAttributedwithString:(NSString*)str
{
NSRange occupiedRange = [str rangeOfString:NSLocalizedString(@"occupied", @"")];
if (occupiedRange.location == NSNotFound)
{
NSLog(@"Not found");
NSAttributedString *attRStr = [[[NSAttributedString alloc] initWithString:str] autorelease];
return (attRStr);
}
else
{
NSString *string = [str substringToIndex:occupiedRange.location];
str = [str substringFromIndex:occupiedRange.location];
NSString *tarGetString = [str substringToIndex:occupiedRange.length];
str = [str substringFromIndex:occupiedRange.length];
CGColorRef colorRed = [[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0] CGColor];
NSNumber *underline = [NSNumber numberWithInt:kCTUnderlineStyleSingle];
CTFontRef sysUITargetFont = CTFontCreateUIFontForLanguage(kCTFontUIFontEmphasizedSystem,20.0, NULL);
NSDictionary *attributesDictTarget = [NSDictionary dictionaryWithObjectsAndKeys:
(id)underline, (id)kCTUnderlineStyleAttributeName,
colorRed, (id)kCTForegroundColorAttributeName,
colorRed, (id)kCTStrokeColorAttributeName,nil];
CGColorRef colorBlack = [[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0] CGColor];
CTFontRef sysUIDefaultFont = CTFontCreateUIFontForLanguage(kCTFontUIFontMessage,20.0, NULL);
NSDictionary *attributesDictDefault = [NSDictionary dictionaryWithObjectsAndKeys:
colorBlack, (id)kCTStrokeColorAttributeName,nil];
NSMutableAttributedString *attMString = [[NSMutableAttributedString alloc] initWithString:string attributes:attributesDictDefault];
NSAttributedString *stringToDraw = [[NSAttributedString alloc] initWithString:tarGetString
attributes:attributesDictTarget];
[attMString appendAttributedString:stringToDraw];
NSAttributedString *stringRest = [[NSAttributedString alloc] initWithString:str
attributes:attributesDictDefault];
[attMString appendAttributedString:stringRest];
NSLog(@"check %@", [attMString string]);
return (attMString);
}
}
文字將動態? – Exploring 2013-04-09 10:22:38
是的,它可以被佔用或bezet – Steaphann 2013-04-09 10:29:24
你想改變文本的外觀只爲佔用或bezet或它可能會有所不同,取決於文本? – Exploring 2013-04-09 10:31:14