Ios drawTextInRect:在UITextView类中
我使用UITextField类中的drawTextInRect:方法创建轮廓文本(具有黑色边框/存储效果的文本) 但是我需要类似的东西来在UITextView中创建相同的大纲文本,但是这里不包括drawTextInRect:方法。如何为textView执行此操作 这是我在UITextField类中使用的代码:Ios drawTextInRect:在UITextView类中,ios,iphone,ios7,uitextview,Ios,Iphone,Ios7,Uitextview,我使用UITextField类中的drawTextInRect:方法创建轮廓文本(具有黑色边框/存储效果的文本) 但是我需要类似的东西来在UITextView中创建相同的大纲文本,但是这里不包括drawTextInRect:方法。如何为textView执行此操作 这是我在UITextField类中使用的代码: - (void)drawTextInRect:(CGRect)rect { CGContextRef c = UIGraphicsGetCurrentContext();
- (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;
如何设置填充颜色?笔画里面的颜色?因为在这里它会自动变成透明色