core-graphics

Create a circle or a disk with antialiasing for retina display

China☆狼群 提交于 2019-12-02 03:11:09
问题 I have creating a circle using CGContextFillEllipseInRect from CoreGraphic . I'm using this circle (which is actually a disk) to replace the thumbImage of an UISlider . The antialiasing is applied by default. But the result on my iPhone 6 is clearly not good. I can clearly see the pixels ,not as much as with the antialiasing off, but way more than the pixels of a normal UISlider. Maybe I'm doing something wrong. So my question is, is there a way to get programmatically the same nice disk than

Create a circle or a disk with antialiasing for retina display

懵懂的女人 提交于 2019-12-02 02:11:24
I have creating a circle using CGContextFillEllipseInRect from CoreGraphic . I'm using this circle (which is actually a disk) to replace the thumbImage of an UISlider . The antialiasing is applied by default. But the result on my iPhone 6 is clearly not good. I can clearly see the pixels ,not as much as with the antialiasing off, but way more than the pixels of a normal UISlider. Maybe I'm doing something wrong. So my question is, is there a way to get programmatically the same nice disk than the one used by default for an UISlider? EDIT: Here is how I create the disk: class func drawDisk

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

Using Core animation to animate StrokeColor

可紊 提交于 2019-12-01 21:07:41
I'm trying to animate CAShapeLayar's strokeColor property. I looked throught the documentation and it was stated that it is an animatable property. The code is working for animating postion.y but not the the strokeColor. I'll be happy to get any kind of help or advice The code I've used: lyr.fillColor = [[UIColor clearColor] CGColor]; lyr.lineWidth = 3.8; lyr.strokeColor = [[UIColor yellowColor] CGColor]; lyr.position = CGPointMake(160, 431); lyr.anchorPoint = CGPointMake(.5f, .5f); [self.view.layer addSublayer:lyr]; CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@

Xcode 8 Beta 4 CGColor.components unavailable

天大地大妈咪最大 提交于 2019-12-01 20:42:21
Whilst the code below worked previously, it has stopped working in Xcode 8 Beta 4, presumably because the components return was a very un-Swift-y C-array of floats, and has been removed. The error is bald - "'components' is unavailable" - and I can't find what has replaced it, if anything. Does anyone know how to produce the same functionality? public var cgColour: CGColor { get { return CGColor(red: self.colourRed, green: self.colourGreen, blue: self.colourBlue, alpha: self.colourAlpha) } set { let comps = newValue.components // No longer available self.colourRed = (comps?[0])! self

Number of alpha pixels in CGContext

我们两清 提交于 2019-12-01 14:38:51
I have a masking CGContext with 2 types of pixels: color and alpha (opaque and transparent pixels). How to calculate percentage of alpha pixels in my context? Jeshua Lacock I didn't test it, but this should do the trick - just pass ReportAlphaPercent a CGImageRef: UIImage *foo; //The image you want to analyze float alphaPercent = ReportAlphaPercent(foo.CGImage); float ReportAlphaPercent(CGImageRef imgRef) { size_t w = CGImageGetWidth(imgRef); size_t h = CGImageGetHeight(imgRef); unsigned char *inImage = malloc(w * h * 4); memset(inImage, 0, (h * w * 4)); CGColorSpaceRef colorSpace =

Core Text in UITableviewCell's content overlapping and repeating and superimpose on the other cells

寵の児 提交于 2019-12-01 14:38:35
I am using Core Text to add text to UITableviewCell's content but arabic content seems to be overlapping and repeating itself as I scroll and superimpose on the other cells. I am also using other elements on the page which appear just fine and are not repeating . Just the Core Text seems to be repeating. I cant figure out why . Here is my code: - (CTFontRef)newCustomFontWithName:(NSString *)aFontName ofType:(NSString *)type attributes:(NSDictionary *)attributes { NSString *fontPath = [[NSBundle mainBundle] pathForResource:aFontName ofType:type]; NSData *data = [[NSData alloc]

Number of alpha pixels in CGContext

寵の児 提交于 2019-12-01 12:56:23
问题 I have a masking CGContext with 2 types of pixels: color and alpha (opaque and transparent pixels). How to calculate percentage of alpha pixels in my context? 回答1: I didn't test it, but this should do the trick - just pass ReportAlphaPercent a CGImageRef: UIImage *foo; //The image you want to analyze float alphaPercent = ReportAlphaPercent(foo.CGImage); float ReportAlphaPercent(CGImageRef imgRef) { size_t w = CGImageGetWidth(imgRef); size_t h = CGImageGetHeight(imgRef); unsigned char *inImage

Core Text in UITableviewCell's content overlapping and repeating and superimpose on the other cells

家住魔仙堡 提交于 2019-12-01 12:42:33
问题 I am using Core Text to add text to UITableviewCell's content but arabic content seems to be overlapping and repeating itself as I scroll and superimpose on the other cells. I am also using other elements on the page which appear just fine and are not repeating . Just the Core Text seems to be repeating. I cant figure out why . Here is my code: - (CTFontRef)newCustomFontWithName:(NSString *)aFontName ofType:(NSString *)type attributes:(NSDictionary *)attributes { NSString *fontPath = [

Textured Line in CG

ぃ、小莉子 提交于 2019-12-01 12:42:07
I am working on a Drawing App for iOS. In this app i need to draw textured lines. For this i am using this method .But texture is so small and not in shape. I want to know what i did wrong and how can i resolve it. Here is my updated code- CGPoint mid1 = midPoint(previousPoint1, previousPoint2); CGPoint mid2 = midPoint(currentPoint, previousPoint1); [curImage drawAtPoint:CGPointMake(0, 0)]; CGContextRef context = UIGraphicsGetCurrentContext(); [self.layer renderInContext:context]; CGContextMoveToPoint(context, mid1.x, mid1.y); CGContextAddQuadCurveToPoint(context, previousPoint1.x,