// make your UITextView as a subclass of UITextView
// and override -drawRect: method in your UITextView subclass
- (void)drawRect:(CGRect)rect
{
self.textColor = [UIColor clearColor];
[self setTypingAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.font, NSFontAttributeName, _textBaseColor, NSForegroundColorAttributeName, nil ]]; // _textBaseColor is any color of your choice
CGRect newRect = CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextDrawingMode(context, kCGTextStroke);
// Make the thickness of the outline shadow. and increase the y position of shadow rect by 2.
CGContextSetLineWidth(context, (TEXTOUTLINE_PERCENT/100 * self.font.pointSize)+1); // TEXTOUTLINE_PERCENT can be 25.
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context, kCGLineCapButt);
CGContextSetStrokeColorWithColor(context, [UIColor clearColor].CGColor);
CGRect shadowrect = newRect;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
shadowrect.origin.y += 0.5;
}
else
{
shadowrect.origin.y += 2;
}
[self.text drawInRect:shadowrect withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.font, NSFontAttributeName, SHADOW_COLOR , NSForegroundColorAttributeName, nil]]; // SHADOW_COLOR can be [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.3]
// Make the thickness of the outline border of the text.
CGContextSetLineWidth(context, TEXTOUTLINE_PERCENT/100 * self.font.pointSize); // TEXTOUTLINE_PERCENT can be 25.
CGContextSetStrokeColorWithColor(context, [[UIColor clearColor] CGColor]);
[self.text drawInRect:newRect withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.font, NSFontAttributeName, self.textOutlineColor , NSForegroundColorAttributeName, nil]];
// Draw filled text. This is the actual text.
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
[self.text drawInRect:newRect withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.font, NSFontAttributeName, _textBaseColor, NSForegroundColorAttributeName,_textBaseColor, NSStrokeColorAttributeName, nil]];
[super drawRect:rect];
}