core-graphics

How to rotate UIBezierPath around center of its own bounds?

徘徊边缘 提交于 2019-12-04 01:49:08
问题 Lets say we have a UIBezierPath... the bounds of which are perfectly square... like this: func getExponentPath(rotate180: Bool) -> UIBezierPath { // establish unit of measure (grid) based on this containing view's bounds... (not to be confused with this bezierpath's bounds) let G = bounds.width / 5 let exponentPath = UIBezierPath() let sstartPoint = CGPoint(x:(3.8)*G,y:(1.2)*G) exponentPath.move(to: sstartPoint) exponentPath.addLine(to: CGPoint(x:(5)*G,y:(1.2)*G)) exponentPath.addLine(to:

iOS Drawing text in the centre of shapes

断了今生、忘了曾经 提交于 2019-12-04 01:18:41
问题 I'm trying to draw text in the centre of shapes in iOS, an example would be Microsoft Office's insert shape see: https://www.dropbox.com/s/cgqyyuvy6hcv5g8/Screenshot%202014-01-21%2013.48.17.png I have an array of coordinates that are used to form the shape, which works fine for creating the actual shape. My first tactic was following this stackoverflow question: Core Text With Asymmetric Shape on iOS however I can only get it to draw the text at the bottom of the shape. Is there any way to

How to draw a circle starting at the top

允我心安 提交于 2019-12-04 01:15:32
问题 I'm working with some example code that draws an arc using CGPaths. I've had a look around and have found documentation but I just can't seem to visualize in my head whats going on in terms of using MoveToPoint, AddLineToPoint etc. I can't 'see' what the code is doing I can just see the result. For example the code below draws an arc a full 360 degrees beginning from the 3 o clock position. For the life of me I can't figure out how to make it begin from the 12 o clock position with actually

UIView shadow and InterfaceBuilder

懵懂的女人 提交于 2019-12-03 23:27:54
I want to add a drop shadow using CALayer to a UI(Image)View. The following code works generally fine previewImage.layer.shadowColor = [[UIColor blackColor] CGColor]; previewImage.layer.shadowOffset = CGSizeMake(1.0f, 1.0f); previewImage.layer.shadowOpacity = 1.0f; previewImage.layer.shadowRadius = 8.0f; However, this only works if I create that view programmatically and add it as a subview to my main view. When that view is set up in InterfaceBuilder and defined as an IBOutlet UIImageView this does NOT work. No shadow appears. So what am I missing here? I'm not sure what the issue is - ensure

Creating a union of 2 bezier paths

家住魔仙堡 提交于 2019-12-03 23:27:06
I have two bezier paths that i'd like to combine to form a union, so that I can stroke the entire outer shape. In my case, it's a speech bubble with a tail, so although it's not a complex shape it would actually be quite hard to create it using one single path. There doesn't appear to be a Core Graphics API for creating unions. Am I wrong? If I'm not, does anyone know of a library that can handle this? I've search GitHub to no avail. UIBezierPath does that if you are working with closed shapes. UIBezierPath *firstPath = [UIBezierPath bezierPath]; // build your path UIBezierPath *secondPath =

How to attach CGPDFDocument/CGPDFPage to MFMailComposeViewController

倾然丶 夕夏残阳落幕 提交于 2019-12-03 23:01:39
问题 I have a muti page pdf document stored on local storage. I want to extract any page out of that pdf doc and convert it into NSData to attach it with 'MFMailComposeViewController'. With the following lines of code, I can easily retrive the required page... CGPDFDocumentRef pdfDoc=CGPDFDocumentCreateWithURL(pdfURL); CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfDoc, pageNumber); But I am unable to find a way to convert pdfPage into NSData so that I can attach it with mail. NOTE: The

Mac OS X: Convert between NSView coordinates and global screen coordinates

半世苍凉 提交于 2019-12-03 22:55:50
I have the following situation in my multi-monitor setup: In this example I want to position a window exactly at the coordinates depicted with the yellow arrow. All I do have however, are the coordinates of an NSView that is a subview of the contentView of an NSWindow that spans the entire (bigger,upper) secondary monitor. Here's how the global coordinate space is defined: {0,0} is the coordinate of the upper left corner of my laptop screen. (green) {-296, -1080} is the coordinate of the upper left corner of my second screen (black) {0, 800} is the coordinate of the lower left corner (no arrow

How can I save a Bitmap Image, represented by a CGContextRef, to the iPhone's hard drive?

亡梦爱人 提交于 2019-12-03 22:28:39
I have a little sketch program that I've managed to throw together using Quartz2D, but I'm very new to the iOS platform and I'm having trouble figuring out how to allow the user to save their sketch. I have a CGContextRef that contains the sketch, how can I save it so that it can later be retrieved? Once it's saved, how can I retrieve it? Thanks so much in advance for your help! I'm going to continue reading up on this now... There are different types of CGContexts. You are most likely having a screen based context, but you would need either a bitmapContext or a pdfContext, to create a bitmap

Getting NSImage from CGImageRef

末鹿安然 提交于 2019-12-03 22:14:32
I am trying process an image in CoreGraphics and then return the processed image back to an NSImage for saving and displaying. I have ample resources on how to perform these functions in iOS but the helper methods seem to be missing in NSImage . In iOS the class method is imageWithCGImage: , how can you do this in Mac OS? The matching method in NSImage is initWithCGImage:size: . The second argument takes the image's size in points. The factor between the size in pixels (of the CGImage) and the size in points is the scale factor. So, for example, if you have a 100×100px CGImage, and pass a size

Objective C: Using UIImage for Stroking

依然范特西╮ 提交于 2019-12-03 22:14:12
问题 I am trying to apply a texture for my brush but i'm really having a hard time figuring how it is done. Here's the image of my output. I used an UIImage that just follows the touch on the screen but when i swipe it faster the result is on the right side "W", and on the left side that's the result when i swipe it slow. i tried using the CGContextMoveToPoint and CGContextAddLineToPoint i don't know how apply the texture. Is it possible to use UIImage for the stroke texture? Here's my code