Mac Cocoa |
Author |
Message |
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sun Oct 26, 2008 12:32 am Post subject: Graphics & Quartz |
|
|
Matt Gallagher: Drawing gloss gradients in CoreGraphics
"This post presents a function — DrawGlossGradient(CGContextRef context,
NSColor *color, NSRect inRect) — that will draw a "gloss" gradient in a single
statement. All colors in the gradient are calculated from the single color
parameter." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Thu Jan 15, 2009 7:58 pm Post subject: |
|
|
iphonexe.com - UIKit/CoreGraphics vs. AppKit/Cocoa (blog)
"The iPhone compiler, unfortunately, does not include any of the Cocoa/AppKit
UI-oriented classes. This means your stuck with (sigh) CoreGraphics, or the
CG- prefix, and the iPhone-specific UIKit with the UI- prefix, rather than the
NS- (AppKit/Cocoa) classes you used to know and love." |
|
Back to top |
|
|
XNote Kapetan
Joined: 16 Jun 2006 Posts: 532
|
Posted: Mon Feb 16, 2009 4:41 pm Post subject: |
|
|
MF - Drawing/Filling Image in an Ellipse
"What I meant to say was, that I want the image to be displayed, intact
(without clipping) inside the ellipse." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sat Apr 11, 2009 12:21 am Post subject: |
|
|
MF - How to draw line in NSView?
"First lock the view before drawing into it: [myView lock]. Then use NSBezier-
Path to describe the line (see NSBezierPath docs for this) and then [myPath
stroke] method to draw the line into the view." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Sat May 02, 2009 7:59 pm Post subject: |
|
|
SO - Changing colors with CGContextStrokePath
"If you want to use multiple colours with the same Graphics Context, then it
appears that you need to make multiple calls to CGContextStrokePath() cha-
nging the value of RGBStrokeColor() on the Graphics Context between calls." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Fri May 08, 2009 12:55 pm Post subject: |
|
|
MF - I need to use custom drawing to draw an NSImage
"CoreAnimation might work well for this. Put the image on one layer, then
have the rects on layers above it and let the compositing system handle it." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Wed Jul 08, 2009 3:38 pm Post subject: |
|
|
markj.net - What Color is My Pixel? Image based color picker on iPhone
"I’ve wrapped this up in ColorPickerImageView, a subclass of UIImageView.
When you tap it, it uses this approach to get the pixel color you tapped. You
can also register a simple delegate with it to get a callback with the picked co-
lor. You put your own image in it, so you can make it a little color pallet in a
corner or make it fill the screen. As it’s derived from UIImageView, you use
it just like UIImageView in code or in Interface Builder." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Wed Aug 19, 2009 1:36 am Post subject: |
|
|
iphonedevsdk.com - Resize Image High Quality
"I have done lots of searching for a way to resize images via the iPhone SDK
and I have come across a few methods which "work" but the resulting image
does not look nearly as good as if you took the full resolution image and told
it to draw inside a rectangle; which obviously if you could use the same inter-
polation routines as that drawing call does you should be able to get the same
result." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Fri Aug 21, 2009 2:52 pm Post subject: |
|
|
so - Convert to grayscale - too slow
"I've made a class that converts an image into grayscale. But it works way
too slow. Is there a way to make it work faster?" |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Sun Aug 30, 2009 7:52 pm Post subject: |
|
|
markj - Fixing Blurry Subviews
"It didn’t quite work though, because the detail view came out really blurry.
It didn’t look blurry in Interface Builder, but both on the simulator and the
iPhone it looked terrible... I spent hours changing font properties and colors,
thinking it was some weird text anti-aliasing gone wrong, but it always came
out blurry. Can you guess the problem?" |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sat Nov 21, 2009 1:19 am Post subject: |
|
|
so - Where can I find examples of Quartz 2D drawing on the iPhone?
"As an example, we designed the Core Plot framework around Core Anima-
tion, using Quartz drawing, because we can have an almost identical code-
base between our Mac and iPhone versions of the framework. That's at least
one large piece of sample code that you can look at." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sun Nov 22, 2009 1:43 am Post subject: |
|
|
Open Sword Group & Andy Matuschak - Pixen
"Pixen is like a very powerful MSPaint or a simpler, more agile Photoshop.
And best of all, it's Free!" |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Tue Dec 01, 2009 11:26 pm Post subject: |
|
|
MF - RGBA Color Information of CGPoint
"What frameworks or apple example code should i research in order to
receive pixel color information (RGBA) of CGPoint?" |
|
Back to top |
|
|
XNote Kapetan
Joined: 16 Jun 2006 Posts: 532
|
Posted: Sun Dec 27, 2009 10:54 pm Post subject: |
|
|
so - Drawing an equation in Quartz
"Is there a built-in way to draw a graph of a math formula in Quartz? For
beginning it will be only a parabola (y=ax^2+bx+c) but the equation itself
will become more complex in the future.
It may be pretty slow if I will draw the parabola using my own algorithm
(from separate lines or dots)." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Fri Jan 22, 2010 8:53 pm Post subject: |
|
|
MF - Cocoa/Quartz Drawing: "glowing" geometry question
"I'm not trying to make a game or anything, just playing around with dra-
wing some simple shapes on a dark gradient using core animation layers,
but I'm not sure what drawing parameters are involved with achieving the
above look of being "luminous bodies." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Thu Feb 18, 2010 10:06 pm Post subject: |
|
|
SO - Dump transformed CALayers and sublayers to UIImage
"It seems renderInContext extracts the raw image from the layer and ren-
ders it in the context. What I need is to extract what is been seen on the
view... in other words: if the layer is seen in perspective, this perspective
must be present on the UImage." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Thu Apr 22, 2010 9:23 pm Post subject: |
|
|
ars - iPhone development: accessing UIColor components
"In this post, I'm going to introduce a number of ways I have expanded
UIColor and show where the class could be built upon even further. Much
of this work is built on the feedback and contributions of Hans Larsen, Ke-
vin Ballard, and Emanuele Vulcano, all of whom helped nursemaid this lit-
tle project along in #iphonedev over at irc.freenode.net." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Sun Jul 18, 2010 5:26 pm Post subject: |
|
|
iphonedevsdk.com - Rotating an image according to the users'
finger location
"Basically, I'm working on a concept of a game which involves a cannon in
the bottom left hand corner. I have two images for the cannon - one that is
the base of the cannon, which is static (and will stay that way), and one that
is the top of the cannon, which will angle towards the finger location (so that
the user can direct the cannon." |
|
Back to top |
|
|
XNote Kapetan
Joined: 16 Jun 2006 Posts: 532
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sun Jul 18, 2010 9:55 pm Post subject: |
|
|
coneybeare.net - How to Make Custom Drawn Gradient Backgrounds
in a Grouped UITableView with Core Graphics
"... Core Graphics. It was meant as a way to customize the background of
a cell before the 3.0 sdk came out, but I used it as a basis for my code to
draw a gradient! It needed tweaking and optimization, but after a little bit
of hacking away at it, I was able to get it to work nicely. I present to you
the UACellBackgroundView." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Aug 02, 2010 9:50 pm Post subject: |
|
|
joris.kluivers.nl - Scale an image the thread safe way
"Resizing an image (or any graphics operation for that matter) is cpu inten-
sive and takes a little time. The crashes started to appear when I moved the
call to - [UIImage imageScaledToSize:] to a background thread to prevent
locking up the UI when processing multiple images." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Aug 02, 2010 10:56 pm Post subject: |
|
|
iphonedevsdk.com - Background threads and graphics
"... by explicitly calling CGBitmapContextCreate(), CGContextDrawImage(),
and CGBitmapContextCreateImage(), you can resize the image without
messing with the UIKit's graphics context stack.
The problem now is dealing with the damn imageOrientation field of the
image, which seems to be handled automatically when you use the UIKit.
Also it took me a while to realize that if I wanted to get meaningful values
in this field for images taken from the camera in-app, I had to first enable
device orientation notifications." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Wed Aug 04, 2010 1:45 pm Post subject: |
|
|
Trevor's Bike Shed - Resize a UIImage the right way
"The source code to the categories can be downloaded from the links below
or as a single archive. If you are an experienced iPhone programmer, you
can probably grab the files and start using them right away. Continue read-
ing for more detail on how to apply them, as well as a run-down of the pro-
blems that prompted their creation."
And: mprovement to Trevor Harmon’s UIImage+Resize.m
"I found a good post on Robert Clark’s Niftybean blog, “Selecting re-
gions from rotated EXIF images on iPhone” with code for adapting the a
crop rect based on a UIImage’s imageRotation. Adding this to cropped-
Image I then only needed to finally rotate the resulting CGImageRef, for
I only needed to slightly generalize the private resizeImage:transform:…
helper method and then use it to rotate the resulting cropped image to
match imageRotation." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Fri Aug 06, 2010 11:04 pm Post subject: |
|
|
MF - How do I make a spot glow?
"For instance, if I want to write an app where if you touch a spot on the
screen, the spot would glow, and when you remove your finger, the spot
would gradually dim and turn invisible." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sat Sep 04, 2010 8:30 pm Post subject: |
|
|
so - What are some great Quartz 2D drawing tutorials?
"I devoted an entire class to Quartz 2D drawing last semester in my advan-
ced iPhone development course. The video for that is available on iTunes U,
along with the rest of the class. The course notes for that session can be fo-
und here, and I created a sample application to show off some more advan-
ced Quartz drawing concepts." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Thu Sep 09, 2010 1:46 pm Post subject: |
|
|
iphonedevbook.com - VectorSprite scales differently on simulator and
device
"The way this works is through the contentScaleFactor, as well as a few other
scale related properties on some other classes.
Generally you can just ignore it and supply the doubled resolution images
and it just 'works'. However since the vector sprites are drawing directly into
the graphics context then your code needs to be aware of the scale factor to
function properly. (which you have discovered)." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Thu Sep 16, 2010 12:21 am Post subject: |
|
|
objcolumnist.com - Rounding the corners of an UIView
"Although UIView does not allow you round its corners, CALayer does, and
every UIView is backed by a CALayer." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Fri Oct 15, 2010 4:55 pm Post subject: |
|
|
so - iPhone, need the dark blue color as a UIColor (used on tables
details text) #336699
"I wrote a category for UIColor to convert hex-style colors to UIColors"
Code: | + (UIColor *)colorWithHex:(UInt32)col {
unsigned char r, g, b;
b = col & 0xFF;
g = (col >> 8) & 0xFF;
r = (col >> 16) & 0xFF;
return [UIColor colorWithRed:(double)r/255.0f green:(double)g/255.0f blue:(double)b/255.0f alpha:1];
}
UIColor *newColor = [UIColor colorWithHex:0x336699]; |
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Thu Oct 21, 2010 8:24 pm Post subject: |
|
|
MF - Drawing a PNG to a CALayer
"I think if you have a drawLayer method then you are telling CALayer that
your delegate will do all the drawing for that layer. As you are doing nothing
in drawLayer nothing will get drawn. Either remove that method or implem-
ent it correctly to draw the contents." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Thu Nov 11, 2010 5:27 pm Post subject: |
|
|
MF - NSBezierPath tutorial
"I've been trying to learn to draw simple shapes in Objective-c (I'm new to
the language) and I am having trouble figuring it out." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Wed Nov 24, 2010 10:17 pm Post subject: |
|
|
so - Is there an easy way or library available to let text glow?
"You can do this using pure Quartz drawing. Within -drawRect: for a UIView
or -renderInContext: for a CALayer, the following code will draw text and
apply a glow around it:"
Code: | CGContextSetShadowWithColor( context, CGSizeMake( 0.0, 0.0 ), 20.0f, glowColor );
[text drawAtPoint:CGPointMake(0.5f, 0.5f) withFont:[UIFont fontWithName:@"Helvetica" size:16.0f]];
|
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sat Nov 27, 2010 8:58 pm Post subject: |
|
|
adc - Creating a CGPathRef From an NSBezierPath Object
"To ensure that the returned path returns correct results during hit detection,
this method implicitly closes the last subpath if your code does not do so
explicitly. Quartz requires paths to be closed in order to do hit detection on
the path’s fill area." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Wed Dec 08, 2010 8:24 pm Post subject: |
|
|
Ray Wenderlich - Core Graphics 101: Shadows and Gloss
"In this article, we’ll move on to customizing the header for the table. Along
the way, we’ll solidify some of our existing knowledge, and learn how to draw
shadows and gloss effects!" |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Dec 20, 2010 2:34 pm Post subject: |
|
|
SO - CALayer and CGGradientRef anti-aliasing?
"Basically it seems like the CGDrawRadialGradient function only has aliasing
at the starting circle, not the ending one." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Mon Jun 17, 2013 4:57 pm Post subject: |
|
|
Erica Sadun - Taking Charge of UIView Transforms in iOS Programming
"Affine transforms represent one of the most-used and most-feared fea-
tures in UIKit. Much of the transform's frustration factor ties into the opaq-
ueness of the underlying structure and the lack of easy human-relatable
methods. Erica Sadun, author of The iOS 5 Developer's Cookbook: Expan-
ded Electronic Edition: Essentials and Advanced Recipes for iOS Program-
mers, helps you conquer that opaqueness by offering a number of simple
tweaks that transform (if you pardon the pun) the CGAffineTransform
structure into friendlier Objective-C-based properties and methods." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Tue Jul 02, 2013 7:27 pm Post subject: |
|
|
raywenderlich.com How To Create a Rotating Wheel Control with UIKit
"This component is intuitive to use because it resembles many similar
controls we use in real life to make choices. For example:
* A ship’s wheel allows the captain to choose the direction of travel.
* To set the volume of your stereo, you use a rotary knob.
* You might also remember that we used to call people using rotary dial telephones.
Such shared knowledge allows us to recognize the “possible uses” of a rotary
wheel, even when it’s a virtual wheel." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Tue Aug 13, 2013 5:01 pm Post subject: |
|
|
Eric Yuan - Rotation Pie Chart
"Demonstrate a pie chart which can rotate."
Links to Similar Source Code:
1. Percentage Chart
UIView object that animates a chart showing a percentage value. Rotation pie chart.
2. Rotation pie char
Rotation pie chart demo. The pie chart can be rotated by finger.
3. Core Animation Pie Chart
Pie Chart built using CAShapeLayers, a CADisplayLink and custom layer
properties. The pie chart contains the following features: 1. add new slices
(animated) 2. remove selected slice (animated) 3. update existing pie
values (animated) 4. interactive slice selection (tap and/ or move your
finger) The view uses a data source (number of slices, slice value) and
delegate (selection tracking)
4. XYPieChart
XYPieChart is an simple and easy-to-use pie chart for iOS app. It has the
following features: - Customized color for slices (default color supported),
animated insert/delete slice(s) - slice selection animation - text label
option of showing percentage or actual value - text label auto-hide when
slice is too small - customizable text label font and relative postion - pie
opening/closing animation - pie starting angle support - ARC support -
interface builder support |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Tue Nov 19, 2013 11:23 pm Post subject: |
|
|
PaintCode - Drawing Code for iOS 7 Rounded Rectangles
"In iOS 7, Apple introduced a slightly different icon shape – it is no longer
a simple rectangle with circular arcs in corners. The old design produced a
subtle but noticeable “hump” in places where arc touches some of the stra-
ight lines. The new iOS 7 icon shape looks more “organic” and eliminates
this effect." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Sat Oct 04, 2014 8:51 pm Post subject: |
|
|
QuartzCode Blog - Apple Watch Animation Explained and Recreated using QuartzCode
"After watching Apple Watch transition animation, I immediately think
how to reproduce this animation in QuartzCode. I’m not gonna explain
full tutorial, however I’ll explain some important techniques to create this
animation. However you can download full project below to try it yourself
using QuartzCode." |
|
Back to top |
|
|
delovski
Joined: 14 Jun 2006 Posts: 3524 Location: Zagreb
|
Posted: Fri Jun 16, 2017 4:24 pm Post subject: |
|
|
lboc - UIKit #311: Round Corner Improvements
"This approach works great for rounding all four corners of a view. But what
if we wanted to round only some of the four corners? Previously we'd need
to drop down and create our own mask layer, giving it a path we created
manually. Bummer.
iOS 11 makes this way easier." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Fri Aug 25, 2023 4:09 pm Post subject: |
|
|
so - NSView's Drawing Context
"You need to use lockFocus: if you want to draw outside drawRect: Here is
the excerpt from documentation of NSView:
If you don't use a display... method to draw an NSView object, you must
invoke lockFocus before invoking methods that send commands to the
window server, and must balance it with an unlockFocus message when
finished.
Hiding or miniaturizing a one-shot window causes the backing store for that
window to be released. If you don't use the standard display mechanism to
draw, you should use lockFocusIfCanDraw rather than lockFocus if there is a
chance of drawing while the window is either miniaturized or hidden." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Sat Aug 26, 2023 8:42 am Post subject: |
|
|
Code: | CGMutablePathRef fillPath = CGPathCreateMutable();
CGPathMoveToPoint(fillPath, NULL, x, y);
CGPathAddLineToPoint(fillPath, NULL, x, y);
CGPathAddLineToPoint(fillPath, NULL, x, y);
CGPathCloseSubpath(fillPath);
CGContextAddPath(context, fillPath);
[self.areaFill fillPathInContext:context];
CGContextAddPath(context, fillPath);
CGPathRelease(fillPath);
|
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Thu Sep 07, 2023 7:00 pm Post subject: |
|
|
so - iOS Core Graphics: Draw ONLY shadows of a CGPath
"I suggest you set the context's clipping path to the inverse of the shape's
path, configure the shadow, and fill the shape normally, with full opacity. The
clipping path will mask out the fill color, and only the shadow would remain.
The trick is using CGContextEOClip and an additional rectangle subpath to set
the clipping area to whatever is not covered by the original path. This will work
for any path that is not self-intersecting." |
|
Back to top |
|
|
|