quartz-graphics

How do I create a CGRect from a CGPoint and CGSize?

江枫思渺然 提交于 2019-12-02 17:51:34
I need to create a frame for a UIImageView from a varying collection of CGSize and CGPoint , both values will always be different depending on user's choices. So how can I make a CGRect form a CGPoint and a CGSize ? Thank you in advance. Two different options for Objective-C: CGRect aRect = CGRectMake(aPoint.x, aPoint.y, aSize.width, aSize.height); CGRect aRect = { aPoint, aSize }; Swift 3: let aRect = CGRect(origin: aPoint, size: aSize) Building on the most excellent answer from @Jim, one can also construct a CGPoint and a CGSize using this method. So these are also valid ways to make a

How to draw a shape on top of a UIImage while respecting the image's alpha mask

若如初见. 提交于 2019-12-02 17:20:39
I need a UIImageView that can draw itself in color or b/w according to a flag: BOOL isGrey; I'm trying to do it by drawing a black rectangle on top of the original image with the Quartz blendmode set to Color. This works except it doesn't respect the image's alpha mask. See illustration: alt text http://img214.imageshack.us/img214/1407/converttogreyscaleillo.png Searching Google and SO, I found and tried several solutions but none respect the mask either. Here is the code that produces the 'What I get' image above: - (void)drawRect:(CGRect)rect { if (isGrey) { CGContextRef context =

Using cornerRadius on a UIImageView in a UITableViewCell

六月ゝ 毕业季﹏ 提交于 2019-12-02 17:17:48
I'm using a UIImageView for each of my UITableViewCells , as thumbnails. My code uses SDWebImage to asynchronously grab those images from my backend and load them in, and then caching them. This is working fine. My UIImageView is a 50x50 square, created in Interface Builder. Its background is opaque, white color (same as my UITableViewCell background color, for performance). However, I'd like to use smooth corners for better aesthetics. If I do this: UIImageView *itemImageView = (UIImageView *)[cell viewWithTag:100]; itemImageView.layer.cornerRadius = 2.5f; itemImageView.layer.masksToBounds =

iOS: How do you measure the width and height of a string using Quartz?

蓝咒 提交于 2019-12-02 16:46:40
Before I ask my questions, this is from Apple's documentation re: how to determine the width of a string using Quartz: If text measurements are important to your application, it is possible to calculate them using Quartz 2D functions. However, you might first consider using ATSUI, whose strength is in text layout and measurement. ATSUI has several functions that obtain text metrics. Not only can you obtain after-layout text metrics, but in the rare cases you need them, you can obtain before-layout text metrics. Unlike Quartz, for which you must perform the calculations yourself, ATSUI computes

Changing color space on and image

隐身守侯 提交于 2019-12-02 16:43:16
问题 I'm creating a mask based on DeviceGray color space based image. What basically I want to do is to change all sorts of gray (beside black) pixels into white and leave black pixels as they are. So I want my image to be consisted with black and white pixels. Any idea how to achieve that using CoreGraphics means ? Please dont offer running all over the pixels in the loop 回答1: Use CGImageCreateWithMaskingColors and CGContextSetRGBFillColor together like this: CGImageRef myMaskedImage; const

How do I create a grid of icons like the iPhone home screen?

China☆狼群 提交于 2019-12-02 15:19:15
How should I go about creating a UI similar to the Springboard (home screen) on the iPhone? I'd like a grid of evenly spaced buttons with images where I can respond to the button tap. Is the UITable a good fit? Should I use a plain UIView and position the icons manually in DrawRect? Is there an alternative that will automatically evenly space the buttons, allow reorganization, and adjust the layout according to the iPhone orientation? I come from a C#/Winforms background and am just now starting iPhone development on the Open Toolchain with 2.2.1 headers. You need to add your icons (which are

Draw a perfect circle from user's touch

血红的双手。 提交于 2019-12-02 13:47:17
I have this practice project that allows the user to draw on the screen as they touch with their fingers. Very simple App I did as exercise way back. My little cousin took the liberty of drawing things with his finger with my iPad on this App (Kids drawings: circle, lines, etc, whatever came to his mind). Then he started to draw circles and then he asked me to make it "good circle" (from my understanding: make the drawn circle perfectly round, as we know no matter how stable we try to draw something with our finger on the screen, a circle is never really as rounded like a circle should be). So

Changing color space on and image

两盒软妹~` 提交于 2019-12-02 10:02:34
I'm creating a mask based on DeviceGray color space based image. What basically I want to do is to change all sorts of gray (beside black) pixels into white and leave black pixels as they are. So I want my image to be consisted with black and white pixels. Any idea how to achieve that using CoreGraphics means ? Please dont offer running all over the pixels in the loop Use CGImageCreateWithMaskingColors and CGContextSetRGBFillColor together like this: CGImageRef myMaskedImage; const CGFloat myMaskingColors[6] = { 0, 124, 0, 68, 0, 0 }; myColorMaskedImage = CGImageCreateWithMaskingColors (image,

Quartz PDF API Causing Out of Memory Crashes

夙愿已清 提交于 2019-12-02 01:21:44
I'm having crashing issues using the Quartz PDF API for iOS. At the moment I am compiling with the SDK 4.0 GM Seed and running on my 3.2 iPad (I have tried using the 3.2 SDK with identical results). All the code I am using is based on the standard Apple Quartz documentation and from various sources around the internets. So I can't image I'm doing something drastically different or wrong. The code runs perfectly in the Simulator (all versions, it's a Universal app) and even while using the "Simulate Memory Warning" function. I've used the Leaks tool and there are no leaks that it finds. Build

Cocoa Touch - Adding texture with overlay view

霸气de小男生 提交于 2019-12-02 00:52:26
I have a set of tiles as UIViews that have a programmable background color, and each one can be a different color. I want to add texture, like a side-lit bevel, to each one. Can this be done with an overlay view or by some other method? I'm looking for suggestions that don't require a custom image file for each case. This may help someone, although this was pieced together from other topics on SO. To create a beveled tile image with an arbitrary color for normal and for retina display, I made a beveled image in photoshop and set the saturation to zero, making a grayscale image called tileBevel