2013-03-27 3 views
0

Я рисую текстовое поле, и я добавил текстовое поле в UIView. Текст находится в пределах пути. Он рисует правильно, но содержимое начинается внизу и заканчивается вверху. Есть ли способ исправить это?coretext показывает текст снизу вверх текстового поля

Вот мой код:

// Draw text into a circle using Core Text and Quartz 
- (void) drawRect:(CGRect)rect 
{ 
[super drawRect: rect]; 

CGContextRef context = UIGraphicsGetCurrentContext(); 
self.layer.rasterizationScale = [[UIScreen mainScreen] scale]; 

// Flip the context 
CGContextTranslateCTM(context, 0, 3); 
CGContextSetTextMatrix(context, CGAffineTransformIdentity); 

CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0f, -1.0f)); 


// Stroke that path 
CGContextAddPath(context, backPath); 
CGContextSetLineWidth(context, 1.0f); 
//[[UIColor blackColor] setStroke]; 
CGContextStrokePath(context); 

// Fill that path 
CGContextAddPath(context, backPath); 
[[UIColor whiteColor] setFill]; 
CGContextFillPath(context); 

CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)string); 
CTFrameRef theFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, string.length),backPath, NULL); 
CTFrameDraw(theFrame, context); 

CFRelease(framesetter); 
CFRelease(theFrame); 
CFRelease(backPath); 

} 

Это, как я сделать путь:

- (id) initWithAttributedString: (NSAttributedString *) aString path: (vector<ofPoint>)paths 
{ 
backPath = CGPathCreateMutable(); 

CGPathMoveToPoint(backPath, NULL, paths[0].x, paths[0].y); // Bottom left 

for(int x=1; x< paths.size(); x++){ 
CGPathAddLineToPoint(backPath, NULL, paths[x].x,paths[x].y); // Bottom right 
} 
CGPathCloseSubpath(backPath); 

if (!(self = [super initWithFrame:CGRectZero])) return self; 

self.backgroundColor = [UIColor clearColor]; 
string = aString; 
return self; 
} 

img

И сделать текстовое поле:

path.push_back(ofPoint(ofGetWidth()/4,ofGetHeight()/4)); 
    // point to user 
// path.push_back(ofPoint((position.x-(ofGetWidth()/4))/2,ofGetHeight()/4)); 
    // point to right top 
    path.push_back(ofPoint(ofGetWidth()/4,ofGetHeight()/4)); 
    // point to end x, pos y user 
    path.push_back(ofPoint((ofGetWidth()/4),(position.y-(ofGetHeight()/4))/2)); 

    path.push_back(ofPoint((position.x-(ofGetWidth()/4))/2-100,(position.y-(ofGetHeight()/4))/2-100)); 

    path.push_back(ofPoint((position.x-(ofGetWidth()/4))/2,(position.y-(ofGetHeight()/4))/2)); 

ответ

2

Вы flippi текстовую матрицу. Вместо этого переверните весь CTM:

CGContextScaleCTM(context, 1, -1); 
CGContextTranslateCTM(context, 0, self.bounds.size.height); 
+0

Хорошо, и где я должен добавить эту деталь? –

+0

Я делал это в прошлом. Но это просто делает textField странным. Чтобы создать текстовое поле выше, я использовал приведенный выше пример, я добавил –