core-graphics

Rounded UIView with Shadow?

别说谁变了你拦得住时间么 提交于 2019-12-24 07:46:17
问题 So using this link: How do I draw a shadow under a UIView? And this link: http://iphonedevelopment.blogspot.com/2008/11/creating-transparent-uiviews-rounded.html I came upon this implementation: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CGContextSetShadow(context, CGSizeMake(-15.0f, 20.0f), 5.0f); CGContextSetLineWidth(context, strokeWidth); CGContextSetStrokeColorWithColor(context, self.strokeColor.CGColor);

Why does my Coregraphics drawingcode cause lag?

丶灬走出姿态 提交于 2019-12-24 07:38:23
问题 I'm working on an drawing app for iPhone. It works fine for like 5 seconds in the iPhone simulator but as more I draw it gets more laggy. When I test it on the device it gets even more laggy and I can't even draw a simple tree. When I check how high percent the processor is running at in xcode it usually go between 97-100%. Is there any way to fix this? (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; currentPoint = [touch locationInView

Fitting UIBezierPath/CGPath to circle

限于喜欢 提交于 2019-12-24 07:27:38
问题 I need to aspectFit arbitrarily shaped paths to the interior of a circle. I can fit rectangular paths to the circle by calculating the size, building a dest rect, then scaling the path to fit the dest rect. let targetSize = circleDiameter / sqrt(2) let destRect = CGRect(x: 0, y: 0, width: targetSize, height: targetSize) // ... Scale the path to the rect, using boundingBox of path. But the scaling process isn't the issue; it's really how to calculate the required scale. A bounding-box based

Dynamically change position based on scrollView

核能气质少年 提交于 2019-12-24 06:41:38
问题 I have a "U" shaped UIBezierPath which I use as the path for my myImage.layer to animate on. I also have a scrollView. My goal is to have a custom "Pull to Refresh" animation. The problem I am having is that I want my myImage.layer to update based on how much the scrollView scrolled. As the scrollView is pulled down, the myImage.layer animates along a "U" shape path . This is the path in my code which I created as a UIBezierPath . This is how I calculate how far the scrollView is pulled down:

Xcode 8 CoreGraphics issue with iPhone 7 (running iOS 10)

无人久伴 提交于 2019-12-24 05:45:16
问题 I'm using an iPhone 7 running iOS 10 (doesn't appear to matter which version of iOS 10, but it has to be an iPhone 7 device...even an iPhone 6s with the same version of iOS 10 doesn't have this issue). Unfortunately, I don't have the ability to try an iPhone 7 running iOS 9 or below. In my app, I'm using this method to mask an image with another image: - (UIImage *)imageWithMask:(UIImage *)maskImage { UIImage *returnImage = nil; CGImageRef maskRef = maskImage.CGImage; CGImageRef mask =

How to recolor an image using CoreGraphics?

会有一股神秘感。 提交于 2019-12-24 02:27:09
问题 I have a picture in shades of gray. Is it possible to recolor the image in shades of other (arbitrary) color? Something like on the picture below. I think I can do that by accessing each pixel of the image and changing it as necessary, but I think that there might be a better way. I would like to do all this using CoreGraphics. 回答1: I solved the task using following code: CGContextSaveGState(bitmapContext); CGContextSetRGBFillColor(bitmapContext, red, green, blue, alpha);

Ios drawing lines animated

天涯浪子 提交于 2019-12-24 01:02:02
问题 I have a view in which I have multiple horizontal lines (like a horzontal dial). I want to animate the horizontal movement. It should look like this EDIT: How can I do this? As far as I understood I can't use CoreAnimation. Furthermore I wan't to be able to simulate different kinds of speed. How would the updatemethod work? Do I change the draw time, or distance? I know I could solve this with a scrollview, but I would prefer not to use it. Thanks! 回答1: If I've understood what you are trying

Quantize Image, Save List of Remaining Colors

末鹿安然 提交于 2019-12-24 00:34:23
问题 Is there a library I can use that will allow me to quantize images on an iPhone? I want to quantize the images down to maybe 8 colors and record either hex or rgb values for each color remaining after the quantization. 回答1: Shouldn't be too hard to do this yourself. Get to the pixel data and then just iterate through and quantize. Here's how to get the pixel data: (This code is from Erica Sadun's Cookbook samples, I believe) // Courtesy of Apple, Create Bitmap with Alpha/RGB values

Not drawing outside bounds when clipToBounds=NO

牧云@^-^@ 提交于 2019-12-23 18:37:23
问题 I am drawing lines on a map, and I notice that my annotation view isn't covering the entire area of the lines (which is fine, as long as I can draw outside the bounds of the view). Here is a picture of what I'm experiencing. The clipToBounds property is set to NO for the annotation view, and I've added a semi-transparent color to the background so you can see the position of the view. blue line not drawn outside bounds http://img.skitch.com/20100512-qdm18j7x42wptw3cumnr6h271q.jpg The pins

Create image from NSString properly

陌路散爱 提交于 2019-12-23 17:22:25
问题 I am creating a image from string variable. Following is the code snippet to create image -(UIImage *)imageFromText:(NSString *)text FontName:(UIFont *)font { // set the font type and size //UIFont *font = [UIFont systemFontOfSize:20.0]; CGSize size = [text sizeWithFont:font]; UIGraphicsBeginImageContext(size); [text drawAtPoint:CGPointMake(0.0, 0.0) withFont:font]; // transfer image CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES); CGContextSetAllowsAntialiasing