一款以时髦、新潮的方式来使用UIImage的swift插件

github:https://github.com/targetcloud/TGImage

效果截屏

一款以时髦、新潮的方式来使用UIImage的swift插件_第1张图片
图片发自App

代码

UIImageView(image: ({ () -> UIImage in

            var container = UIImage.size(width: 180, height: 20)

                .color(.clear)

                .image

            for i in 0..<7{

                let doti = UIImage.size(width: 20, height: 20)

                    .color(gradient: [UIColor.randomColor(), UIColor.randomColor()], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 1))

                    .corner(radius: 10)

                    .image

                    .position(CGPoint(x: i * 20 + (i + 1) * 3, y: 0))

                container = container + doti

            }

            return container

        })())



UIImageView(image: ({ () -> UIImage in

            var container = UIImage.size(width: 30, height: 120)

                .color(.clear)

                .image

            for i in 0..<4{

                let doti = UIImage.size(width: CGFloat(30 - i * 4), height: CGFloat(30 - i * 4))

                    .color(gradient: [UIColor.randomColor(), UIColor.randomColor()], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 1))

                    .corner(radius: CGFloat(30 - i * 4) * 0.5)

                    .image

                    .position(CGPoint(x: i * 2, y: 30 * i + (i + 1) * 3))

                container += doti

            }

            return container

        })())

效果截屏

一款以时髦、新潮的方式来使用UIImage的swift插件_第2张图片
图片发自App

代码

UIImageView(image: UIImage.size(width: 100, height: 100)

            .color(gradient: [.green, .blue], locations: [0, 1], from: CGPoint(x: 0, y: 1), to: CGPoint(x: 0, y: 0))

            .border(gradient: [.red, .yellow], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 0))

            .border(width: 5)

            .border(alignment: .outside)

            .corner(topLeft: 20)

            .corner(topRight: 50)

            .corner(bottomLeft: 50)

            .corner(bottomRight: 20)

            .image)


UIImageView(image: ({ () -> UIImage in

            let background = UIImage.size(width: 120, height: 120)

                .color(gradient: [.black, .white], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 0, y: 1))

                .corner(radius: 13.5)

                .image

            let circle = UIImage.size(width: 106, height: 106)

                .color(.white)

                .corner(radius: 50)

                .image

            let center = UIImage.size(width: 8, height: 8)

                .color(.black)

                .corner(radius: 3)

                .image

            let clock = background + circle + center

            return clock.with { context in

                context.setLineCap(.round)

                UIColor.black.setStroke()

                context.setLineWidth(2)

                context.move(to: CGPoint(x: clock.size.width / 2, y: clock.size.height / 2))

                context.addLine(to: CGPoint(x: clock.size.width / 2 - 5, y: 15))

                context.move(to: CGPoint(x: clock.size.width / 2, y: clock.size.height / 2))

                context.addLine(to: CGPoint(x: clock.size.width - 25, y: clock.size.height / 2 - 3))

                context.strokePath()

                UIColor.red.setStroke()

                context.setLineWidth(1)

                context.move(to: CGPoint(x: clock.size.width / 2 + 8, y: clock.size.height / 2 - 7))

                context.addLine(to: CGPoint(x: 26, y: clock.size.height / 2 + 35))

                context.strokePath()

                UIColor.red.setFill()

                let rect = CGRect(x: clock.size.width / 2 - 1, y: clock.size.height / 2 - 1, width: 3, height: 3)

                context.fillEllipse(in: rect)

            }

        })())

插件使用大致如上,更多使用方式和查看插件实现代码请移步至

https://github.com/targetcloud/TGImage

你如果觉得赞,请star

666

你可能感兴趣的:(一款以时髦、新潮的方式来使用UIImage的swift插件)