Apple Swift(iOS-CoreGraphics / QuartzCore)-832字节
我为Apple iOS设备完全使用Quartz绘制了形状。不幸的是,这不是一门特别注意大小的语言,因此结果相当大,但是我所能得到的却很小。
UIGraphicsBeginImageContext(CGSize(width:60,height:60));let c=UIGraphicsGetCurrentContext()!;UIColor.lightGray.setStroke();c.addRect(CGRect(x:0,y:0,width:60,height:60));c.move(to: CGPoint(x:20,y:0));c.addLine(to: CGPoint(x:20,y:60));c.move(to: CGPoint(x:40,y:0));c.addLine(to: CGPoint(x:40,y:60));c.move(to: CGPoint(x:0,y:20));c.addLine(to: CGPoint(x:60,y:20));c.move(to: CGPoint(x:0,y:40));c.addLine(to: CGPoint(x:60, y:40));c.strokePath();UIColor.black.setFill();c.addEllipse(in:CGRect(x:22,y:2,width:16,height:16));c.addEllipse(in:CGRect(x:42,y:22,width:16,height:16));c.addEllipse(in:CGRect(x:2,y:42,width:16,height:16));c.addEllipse(in:CGRect(x:22,y:42,width:16,height:16));c.addEllipse(in:CGRect(x:42,y:42,width:16,height:16));c.fillPath();let i=UIGraphicsGetImageFromCurrentImageContext();sub.addSubview(UIImageView(image:i))
感兴趣的人可以阅读的版本:
UIGraphicsBeginImageContext(CGSize(width: 60, height: 60))
let c = UIGraphicsGetCurrentContext()!
UIColor.lightGray.setStroke()
c.addRect(CGRect(x: 0, y: 0, width: 60, height: 60))
c.move(to: CGPoint(x: 20, y: 0))
c.addLine(to: CGPoint(x: 20, y: 60))
c.move(to: CGPoint(x: 40, y: 0))
c.addLine(to: CGPoint(x: 40, y: 60))
c.move(to: CGPoint(x: 0, y: 20))
c.addLine(to: CGPoint(x: 60, y: 20))
c.move(to: CGPoint(x: 0, y: 40))
c.addLine(to: CGPoint(x: 60, y: 40))
c.strokePath()
UIColor.black.setFill()
c.addEllipse(in: CGRect(x: 22, y: 2, width: 16, height: 16))
c.addEllipse(in: CGRect(x: 42, y: 22, width: 16, height: 16))
c.addEllipse(in: CGRect(x: 2, y: 42, width: 16, height: 16))
c.addEllipse(in: CGRect(x: 22, y: 42, width: 16, height: 16))
c.addEllipse(in: CGRect(x: 42, y: 42, width: 16, height: 16))
c.fillPath()
let i = UIGraphicsGetImageFromCurrentImageContext()
sub.addSubview(UIImageView(image: i))
这是iOS模拟器中产生的输出: