oc代码 创建一个纯白的UIImage
时间: 2023-05-30 22:04:44 浏览: 144
iOS中 UIImage根据屏宽调整size的实例代码
以下是Swift代码:
```swift
let size = CGSize(width: 100, height: 100)
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
UIColor.white.setFill()
UIRectFill(CGRect(origin: CGPoint.zero, size: size))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
```
以下是Objective-C代码:
```objc
CGSize size = CGSizeMake(100, 100);
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[[UIColor whiteColor] setFill];
UIRectFill(CGRectMake(0, 0, size.width, size.height));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
```
阅读全文