core-graphics

Get lighter and darker color variations for a given UIColor

会有一股神秘感。 提交于 2020-08-20 17:58:11
问题 How to get different lighter and darker variations of a given UIColor in Swift? 回答1: Updated Use below UIColor Extension: extension UIColor { func lighter(by percentage: CGFloat = 30.0) -> UIColor? { return self.adjust(by: abs(percentage) ) } func darker(by percentage: CGFloat = 30.0) -> UIColor? { return self.adjust(by: -1 * abs(percentage) ) } func adjust(by percentage: CGFloat = 30.0) -> UIColor? { var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0 if self

CGContext.init() — NULL color space no longer allowed

大城市里の小女人 提交于 2020-08-05 07:19:06
问题 TL;DR: In legacy Obj-C code, the color space param value was NULL . That is not allowed in the Swift equivalent. What value to use? I have inherited code that reads: unsigned char pixel[1] = {0}; CGContextRef context = CGBitmapContextCreate( pixel,1, 1, 8, 1, NULL, (CGBitmapInfo)kCGImageAlphaOnly ); The port to Swift 4 CGContext is straightforward, except for that NULL color space value. Using a plausible value, I am getting nil back from CGContext.init?() . My translation is: var pixelValue

How to draw vertical text in UILabel

丶灬走出姿态 提交于 2020-05-22 11:26:46
问题 I'm currently working on drawing vertical Chinese text in a label. Here's what I am trying to achieve, albeit with Chinese Characters: I've been planning to draw each character, rotate each character 90 degrees to the left, then rotating the entire label via affine transformations to get the final result. However, it feels awfully complicated. Is there an easier way to draw the text without complicated CoreGraphics magic that I'm missing? 回答1: Well, You can do like below: labelObject

How to draw heart shape in UIView (iOS)?

萝らか妹 提交于 2020-05-06 06:36:26
问题 I want to create different shapes. Below image is the one of example. Will you suggest me how to different shapes? 回答1: Came across this when I was trying to draw a UIBezier-based heart myself, but was looking for one that looked a bit more like the one on Instagram posts. I ended up writing my own extension/class for it so I thought I'd share it on here in case it's of any use to anyone else who stumbles upon this in future. (This is all in Swift 3) First off, here's the UIBezier extension:

How to draw heart shape in UIView (iOS)?

我的梦境 提交于 2020-05-06 06:36:10
问题 I want to create different shapes. Below image is the one of example. Will you suggest me how to different shapes? 回答1: Came across this when I was trying to draw a UIBezier-based heart myself, but was looking for one that looked a bit more like the one on Instagram posts. I ended up writing my own extension/class for it so I thought I'd share it on here in case it's of any use to anyone else who stumbles upon this in future. (This is all in Swift 3) First off, here's the UIBezier extension:

Drawing warped text on iOS

主宰稳场 提交于 2020-04-08 05:48:05
问题 Using standard APIs available on iOS 9 and later, how can I achieve a warp effect (something like the following image) when drawing text? How I would imagine this might work is by specifying essentially four "path segments" which could be either Bézier curves or straight line segments (whatever single "elements" you can normally create within a CGPath or UIBezierPath ) defining the shape of the four edges of the text's bounding box. This text doesn't need to be selectable. It may as well be

Why is CGImageCreateWithMaskingColors() returning nil in this case?

不羁岁月 提交于 2020-04-07 04:18:01
问题 When I use the following code: UIImage *image=[UIImage imageNamed:@"loginf1.png"]; CGImageRef rawImageRef=image.CGImage; const float colorMasking[6] = {222, 255, 222, 255, 222, 255}; CGImageRef maskedImageRef=CGImageCreateWithMaskingColors(rawImageRef, colorMasking); maskedImageRef is always nil. Why is this, and what can I do to correct this? 回答1: I had the same problem. The CGImageRef you are creating has only 6 bytes for each pixel with byte with no alpha channel. The masking function

Why is CGImageCreateWithMaskingColors() returning nil in this case?

☆樱花仙子☆ 提交于 2020-04-07 04:15:27
问题 When I use the following code: UIImage *image=[UIImage imageNamed:@"loginf1.png"]; CGImageRef rawImageRef=image.CGImage; const float colorMasking[6] = {222, 255, 222, 255, 222, 255}; CGImageRef maskedImageRef=CGImageCreateWithMaskingColors(rawImageRef, colorMasking); maskedImageRef is always nil. Why is this, and what can I do to correct this? 回答1: I had the same problem. The CGImageRef you are creating has only 6 bytes for each pixel with byte with no alpha channel. The masking function

rotate CIImage around center with CIFilter

别说谁变了你拦得住时间么 提交于 2020-03-28 04:15:13
问题 I'm trying to rotate the pixel data of a CMSampleBuffer (coming from the camera) and display it in a UIImageView. I Don't want to rotate the view itself. It has to be the actual pixel data. I grab the feed, convert it to a CIImage and with a CIFilter I rotate it. I'm having trouble with setting the point around which it has to rotate. Right now it rotates around the lower left point. I want to rotate it around its center. func captureOutput(_ captureOutput: AVCaptureOutput!,