Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios drawTextInRect:在UITextView类中_Ios_Iphone_Ios7_Uitextview - Fatal编程技术网

Ios drawTextInRect:在UITextView类中

Ios drawTextInRect:在UITextView类中,ios,iphone,ios7,uitextview,Ios,Iphone,Ios7,Uitextview,我使用UITextField类中的drawTextInRect:方法创建轮廓文本(具有黑色边框/存储效果的文本) 但是我需要类似的东西来在UITextView中创建相同的大纲文本,但是这里不包括drawTextInRect:方法。如何为textView执行此操作 这是我在UITextField类中使用的代码: - (void)drawTextInRect:(CGRect)rect { CGContextRef c = UIGraphicsGetCurrentContext();

我使用UITextField类中的drawTextInRect:方法创建轮廓文本(具有黑色边框/存储效果的文本)

但是我需要类似的东西来在UITextView中创建相同的大纲文本,但是这里不包括drawTextInRect:方法。如何为textView执行此操作

这是我在UITextField类中使用的代码:

- (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];
}

如何在UITextView类中为textView创建类似的解决方案?

您的目标是iOS 6.0+? 这样的方法或许会奏效:

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

享受

Peter,为NSStrokeWidthAttributeName使用负值。在这种情况下,可以为文本设置任何填充颜色

    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;

如何设置填充颜色?笔画里面的颜色?因为在这里它会自动变成透明色