drawTextInRect: in UITextView class

I use the drawTextInRect: method in the UITextField class to create outlined text (text with a black border/store effect).

But I need something similar to create the same outlined text in a UITextView, but the drawTextInRect: method is not included here. How can I do this for a textView?

This is the code I use in the UITextField class:

- (void)drawTextInRect:(CGRect)rect {
    CGContextRef c = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(c, 1);
    CGContextSetLineJoin(c, kCGLineJoinRound);

    CGContextSetTextDrawingMode(c, kCGTextFill);
    self.textColor = [UIColor whiteColor];
    [super drawTextInRect:rect];

    CGContextSetTextDrawingMode(c, kCGTextStroke);
    self.textColor = [UIColor blackColor];
    [super drawTextInRect:rect];
}

How can I create a similar solution for a textView in a UITextView class?

Answers


Are you targeting iOS 6.0+? Something like this should work, perhaps:

        NSAttributedString *yourString = [[NSAttributedString alloc] initWithString:@"Your text" attributes:@{
                                          NSStrokeColorAttributeName:[UIColor redColor],
                                          NSStrokeWidthAttributeName:[NSNumber numberWithFloat:1.0],
                                          NSFontAttributeName:[UIFont systemFontOfSize:24.0f]
                                          }];
        yourTextField.attributedText = yourString;

Enjoy


Peter, use negative value for NSStrokeWidthAttributeName. In this case you can set any fill color for text.

    NSAttributedString *yourString = [[NSAttributedString alloc] initWithString:@"Your text" attributes:@{
                                              NSStrokeColorAttributeName:[UIColor redColor],
                                              NSStrokeWidthAttributeName:[NSNumber numberWithFloat:-1.0],
                                              NSFontAttributeName:[UIFont systemFontOfSize:24.0f],
                                              NSForegroundColorAttributeName:[UIColor greenColor]
                                              }];
            yourTextField.attributedText = yourString;

Need Your Help

How do you pass the labels parameter as a (Mat) to facerecognizer from OpenCV in Java?

java android opencv

So I'm trying to implement the Face Recognizer methods from the contributed section of the OpenCV API on Android. The API documentation can be found here: http://docs.opencv.org/modules/contrib/doc/

How to initialize $id from another function?

php wordpress wordpress-theming

I would like to use $id to echo the id entered in other functions. Here is an example function using id: