图片:
代码:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //建立图片 UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)]; imageView.image=[self createImageWithColor:[UIColor yellowColor]]; [self.view addSubview:imageView]; } //将color转为UIImage - (UIImage *)createImageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return theImage; }