私は画面に描画する方法を持っていますが、それが機能しないという小さな問題を除いて、私のアプリケーションにとって多くの利点があります... まったく。
UIImageView ウィジェットを備えた iOS プログラムがあり、プログラムで描画しようとしていますが、プログラムを実行すると黒く見えます。これは、ヘッダー ファイルのアウトレット宣言です。
@interface TestViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
...そしてこれが私の実装です:
@implementation TestViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIGraphicsBeginImageContextWithOptions(CGSizeMake(400, 400), YES, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat colour[] = { 1, 0, 0, 1 };
CGContextSetFillColor(context, colour);
CGContextFillRect(context, CGRectMake(0, 0, 400, 400));
self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
[self.imageView setNeedsDisplay];
UIGraphicsEndImageContext();
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
TestViewController
ビュー コントローラのデリゲートであり、ウィジェットimageView
のアウトレットです。UIImageView
400 x 400 の赤いボックスを画像に描画し、その画像をウィジェットに割り当てようとしています。setNeedsDisplay
私は十分な措置を求めさえします。
私は何を間違っていますか?ありがとうございました!