UITextAlignment deprecated for NSTextAlignment.

UITextAlignment on NSTextAlignment is injective, not surjective.
There is an equivalence relationship for a subset of NSTextAlignment.

http://en.wikipedia.org/wiki/One-to-one_function
This commit is contained in:
Donald Alan Morrison 2012-09-22 20:56:10 -07:00
parent dca626eab0
commit dec9fff7a7
2 changed files with 14 additions and 8 deletions

View File

@ -118,15 +118,18 @@
} }
size.width = MIN(size.width, origSize.width); size.width = MIN(size.width, origSize.width);
// adjust the point for alignment // adjust the point for alignment
switch (self.textAlignment) { switch ((NSTextAlignment)self.textAlignment) {
case UITextAlignmentLeft: case NSTextAlignmentLeft:
break; break;
case UITextAlignmentCenter: case NSTextAlignmentCenter:
point.x += (origSize.width - size.width) / 2.0f; point.x += (origSize.width - size.width) / 2.0f;
break; break;
case UITextAlignmentRight: case NSTextAlignmentRight:
point.x += origSize.width - size.width; point.x += origSize.width - size.width;
break; break;
case NSTextAlignmentJustified:
case NSTextAlignmentNatural:
default: break;
} }
[self.text drawAtPoint:point forWidth:size.width withZFont:actualFont lineBreakMode:self.lineBreakMode]; [self.text drawAtPoint:point forWidth:size.width withZFont:actualFont lineBreakMode:self.lineBreakMode];
} else { } else {

View File

@ -637,16 +637,19 @@ static CGSize drawOrSizeTextConstrainedToSize(BOOL performDraw, NSString *string
// draw // draw
if (performDraw) { if (performDraw) {
switch (alignment) { switch ((NSTextAlignment)alignment) {
case UITextAlignmentLeft: case NSTextAlignmentLeft:
drawPoint.x = 0; drawPoint.x = 0;
break; break;
case UITextAlignmentCenter: case NSTextAlignmentCenter:
drawPoint.x = (constrainedSize.width - lineSize.width) / 2.0f; drawPoint.x = (constrainedSize.width - lineSize.width) / 2.0f;
break; break;
case UITextAlignmentRight: case NSTextAlignmentRight:
drawPoint.x = constrainedSize.width - lineSize.width; drawPoint.x = constrainedSize.width - lineSize.width;
break; break;
case NSTextAlignmentJustified:
case NSTextAlignmentNatural:
default: break;
} }
NSUInteger stopGlyphIdx = glyphIdx; NSUInteger stopGlyphIdx = glyphIdx;
NSUInteger lastRunIdx = currentRunIdx; NSUInteger lastRunIdx = currentRunIdx;