奇怪的情况 - 来自苹果的例子有效,但在我稍微改变它们之后,没有显示文本。这段代码正确地绘制了蓝色背景,但无论我做什么都拒绝在其上绘制文本:
#import <UIKit/UIKit.h>
@interface CWnd : UIWindow @end
@implementation CWnd
- (void) drawRect : (CGRect) i_poRect
{
// This is working : windows is blue.
CGContextRef oContex = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor( oContex, 0, 0, 255, 1 );
CGContextFillRect( oContex, i_poRect );
// This is not working : not text is displayed.
CGContextSelectFont( oContex, "Monaco", 10, kCGEncodingFontSpecific );
CGContextSetRGBStrokeColor( oContex, 255, 0, 0, 1 );
CGContextSetRGBFillColor( oContex, 255, 0, 0, 1 );
CGContextSetTextDrawingMode( oContex, kCGTextFill );
CGContextSetTextPosition( oContex, 100, 100 );
CGContextShowText( oContex, "abc", 3 );
}
@end
@interface CDelegate : NSObject <UIApplicationDelegate> @end
@implementation CDelegate
- (void)applicationDidFinishLaunching : (UIApplication *) i_poApp
{
CGRect oRect = [ [ UIScreen mainScreen ] bounds ];
[ [ [ CWnd alloc] initWithFrame : oRect ] makeKeyAndVisible ];
}
@end
int main(int argc, char *argv[])
{
return UIApplicationMain( argc, argv, nil, @"CDelegate" );
}