2
我有一个绘制到屏幕的方法,对于我的应用程序有很多好处,除了它不起作用的小问题...。如何以编程方式绘制到iOS中的显示?
我有一个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
为好措施。
我在做什么错? 谢谢!