Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.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 使用drawRect呈现字符串(\n)中的新行_Ios_Xcode_Newline_Line Breaks - Fatal编程技术网

Ios 使用drawRect呈现字符串(\n)中的新行

Ios 使用drawRect呈现字符串(\n)中的新行,ios,xcode,newline,line-breaks,Ios,Xcode,Newline,Line Breaks,我正在尝试使用drawRect以新行分隔符\n呈现字符串 下面的代码将my字符串呈现为一行,没有换行符,即使我使用的是\n字符。请参见倒数第二行 UIFont *font = [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:fontSize]; CGPoint point = CGPointMake(0,0); CGContextRef context = UIGraphicsGetCurrentContext(); CGCo

我正在尝试使用drawRect以新行分隔符\n呈现字符串

下面的代码将my字符串呈现为一行,没有换行符,即使我使用的是\n字符。请参见倒数第二行

UIFont *font =  [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:fontSize];
CGPoint point = CGPointMake(0,0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth(context, 4.0);
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
CGContextSaveGState(context);
[@"test \n test" drawAtPoint:point withFont:font];

CGContextRestoreGState(context);
使用

- (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode
方法来绘制字符串