core-graphics

Create line extensions for given line created by user

不羁岁月 提交于 2019-12-12 17:09:01
问题 I've been working in an app which I have to capture user's touches and draw a line on the screen. This is working so far. The problem is that I'd like to create some kind of extension for that line that goes from the line start/end to the screen boundaries. It's important to that extension be aligned to the main line. I've been trying to accomplish this for some days but without positive results. My idea was to use some kind of linear equation to represent the line and after create two point

Filter on CALayer except for a shape which is an union of (non necessarily distinct) rectangles

a 夏天 提交于 2019-12-12 15:11:19
问题 I want to apply a CIFilter to a CALayer except for an area which is an union of rectangles. I post my not working code, it does exactly the opposite, i.e. the filter is applied only in the rectangles and not outside! func refreshTheFrameWithEffect() { self.layer!.masksToBounds = true self.layerUsesCoreImageFilters = true self.layer!.needsDisplayOnBoundsChange = true let filter = CIFilter(name: "CICircleSplashDistortion") filter!.setDefaults() self.layer!.backgroundFilters = [filter!] var

CoreGraphics: Image Transparent Background

北战南征 提交于 2019-12-12 14:19:35
问题 I am trying to draw an image with a 2px transparent border: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.0); CGContextAddRect(context, CGRectMake(0.0, 0.0, outputImageSize.width, outputImageSize.height)); CGContextDrawPath(context, kCGPathFill); [image drawInRect:CGRectMake(2.0, ((outputImageSize.height - userPhotoImageSize.height) / 2.0) +2.0, userPhotoImageSize.width -4.0, userPhotoImageSize.height -4.0)]; UIImage *screenshot =

UIView's drawRect not being called when swizzled

末鹿安然 提交于 2019-12-12 14:17:51
问题 I am experimenting with advanced Objective-C methods. What I want to achieve is to append specific drawing code to an existing UIView . I started easily, I went on to declare my own drawRect method in a category: @interface UIView (Swizzled) - (void)my_drawRect:(CGRect)rect; @end Then I swizzled the drawRect method of UIView in the implementation of the category: + (void)load { [self swizzleInstanceMethod:@selector(drawRect:) withMethod:@selector(my_drawRect:) inClass:[UIView class]]; } -

iPhone – Photoshop like effects

ⅰ亾dé卋堺 提交于 2019-12-12 13:29:20
问题 Can I make in iphone multiply, screen, color or other photoshop like effects? 回答1: Check QuartzDemo Focus on Blending Demo ;) 回答2: I attempted to replicate many of the Photoshop functions in iOS in a project here: https://github.com/esilverberg/ios-image-filters 来源: https://stackoverflow.com/questions/1784020/iphone-photoshop-like-effects

UITableViewCell custom CG drawing iOS 7

本小妞迷上赌 提交于 2019-12-12 11:48:57
问题 I have a UITableViewCell subclass with the following drawRect: implementation. It will draw a line at the bottom of the cell, indented by 30 points to match our design. The tableView.separatorStyle is set to UITableViewSeparatorStyleNone in lieu of this custom drawing. - (void)drawRect:(CGRect)rect { [super drawRect:rect]; if (!_hideBottomLine) { CGContextRef ref = UIGraphicsGetCurrentContext(); CGContextSetShouldAntialias(ref, NO); CGContextSetStrokeColorWithColor(ref, [UIColor

iOS: transforming a view into cylindrical shape

折月煮酒 提交于 2019-12-12 11:16:39
问题 With Quartz 2D we can transform our views on the x , y and z axis. In some cases we could even make them look 3D by changing the values of the matrixes. I was wondering if it could be possible to transform a view into a cylinder shape like in the following picture? Please ignore the top part of the cylinder. I am more curious to know whether it would be possible warping an UIView around like the side of the cylinder as in the image. Is that possible only making use of Quartz 2D, layers and

App crashes when using __bridge for CoreGraphics gradient on ARC

☆樱花仙子☆ 提交于 2019-12-12 09:56:57
问题 I'm creating an application for iOS 5 and I'm drawing some gradients. The following gradient code I've always used before ARC, but now it does not work on my device anymore (however, it works on the simulator) when I use it several times (so I suppose it's a memory management issue). Anyways, here's the code: CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat locations[] = { 0.0, 1.0 }; NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor, (__bridge id)endColor

Draw partial image or clipping diagonally using Core Graphics

寵の児 提交于 2019-12-12 09:11:52
问题 I am looking to draw an image using Core Graphics.However I am able to draw the partial image i.e Horizontally & vertically. But instead of it I want to have it in a Diagonal Way.For more clarification, pls refer to below image : Real Image : Required Image Output: Below is the code using to fill the Layer with Color : CGContextRef contextRef = UIGraphicsGetCurrentContext(); CGContextMoveToPoint(contextRef, r.origin.x, r.origin.y ); CGContextAddLineToPoint(contextRef, r.origin.x , r.origin.y)

How to fix the Gradient on text when using an image in swift, as the gradient restarts

夙愿已清 提交于 2019-12-12 08:48:44
问题 I'm trying to create a gradient on text, I have used UIGraphics to use a gradient image to create this. The problem I'm having is that the gradient is restarting. Does anyone know how I can scale the gradient to stretch to the text? The text is on a wireframe and will be altered a couple of times. Sometimes it will be perfect but other times it is not. The gradient should go yellow to blue but it restarts see photo below: import UIKit func colourTextWithGrad(label: UILabel) {