cgcontext

How can I remove a UIView with rounded corners from its parent view?

删除回忆录丶 提交于 2019-12-20 04:20:37
问题 I'm creating an iPad app for 3.2 and later. My app has an overlay view which has a semi-transparency that makes everything below it darker. In the middle of this view I am chopping a hole in this semi-transparency to let part of the background filter through unscathed, with this code: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGRect intersection = CGRectIntersection(hole.frame, rect); CGContextClearRect(context, intersection); } Additionally, the

Drawing into CGImageRef

冷暖自知 提交于 2019-12-18 13:24:03
问题 I want to create a CGImageRef and draw points to it. What context to use to create an empty CGImageRef and be able to draw onto it. CGContextRef or CGBitmapContextRef? If you can provide code to create an empty CGImageRef image and draw to it I would appreciate. 回答1: #define HIRESDEVICE (((int)rintf([[[UIScreen mainScreen] currentMode] size].width/[[UIScreen mainScreen] bounds].size.width )>1)) - (CGImageRef) blerg { CGFloat imageScale = (CGFloat)1.0; CGFloat width = (CGFloat)180.0; CGFloat

How to use NSString's sizeWithFont and drawInRect to workout how much of a string to draw

为君一笑 提交于 2019-12-18 12:03:12
问题 I'm drawing multiple 'pages' of imagery using a CGContext in the iOS. I've used sizeWithFont and drawInRect combinations extensively in my app. What I need to do is split a large chunk of text across multiple pages. I can size it and work out whether or not it needs another page but how do I know where to chop it? Do I have to do an ugly loop to check word by word until I find a string length that perfectly fits the page and then chop the string at that point? Is there a smarter way? Any

UISearchBar CGContext ERROR

和自甴很熟 提交于 2019-12-18 10:37:28
问题 I have a UISearchBar inside a view, whenever I tap on it, after the keyboard comes up - after -(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar it sends this to the console: <Error>: CGContextSetStrokeColorWithColor : invalid context 0x0 . This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will

Custom MKOverlayView line width

与世无争的帅哥 提交于 2019-12-18 04:23:09
问题 I have a custom MKOverlayView, which draws a simple line. In drawMapRect: I am setting CGContextSetLineWidth(context, 30); This looks fine when completely zoomed in, but when you zoom out, the line becomes more and more thin. The MKOverlayView reference says that it automatically scales to the map's zoom level. How can I force it to draw the same width no matter what my zoom level? I notice that MKPolylineView (and MKPolygonView) do this correctly... you can see the line's width resize

Iphone CGContextShowTextAtPoint for Japanese characters

烈酒焚心 提交于 2019-12-17 16:36:00
问题 I am working on an app where I am using CGContextShowTextAtPoint to display text to the screen. I want to also display Japanese characters, but CGContextShowTextAtPoint takes as its input a C string. So either A) How do I change Japanese characters into a C string? If this is not possible, B) How can I manually print Japanese characters to the screen (within the drawRect method). Thanks in advance. 回答1: CoreText can help you: CTFontGetGlyphsForCharacters (iOS 3.2 onwards) maps Unicode

Is it possible to get all uibezerpath from uiview?

 ̄綄美尐妖づ 提交于 2019-12-13 19:36:29
问题 I've been researching and found no answer. Is it possible to get all UIBezierPath from UIView once drawn in UIView if I use CGGontext for drawing it to the view? (if yes, can you give me an idea to how?) The UIBezierPath came from user input, so if the user draws a lot of UIBezierPath, I need all those path and save it to a .svg file. 回答1: Here's a better working example, after testing some of the answers I've given in my commments, this is the one that will return an array of shapelayers, or

Extra line when drawing an arc in swift

浪尽此生 提交于 2019-12-13 12:22:47
问题 I have this kind of code in a swift app and I get an extra greyed line reaching the starting point of the arc. The arc itself is drawn as expected, but it seems like CGContextMoveToPoint is leaving some trace behind before reaching the starting point. override func drawRect(rect: CGRect) { var context:CGContextRef = UIGraphicsGetCurrentContext(); var centerX,centerY,startAngle,endAngle,radius:CGFloat startAngle = CGFloat(M_PI_4) endAngle = -startAngle radius = (rect.height/2) / sin(startAngle

iOS - adjust hue of UIImage

拟墨画扇 提交于 2019-12-13 05:28:06
问题 Is it possible to adjust Hue of the UIImage/CGContextRef? I have tried to blend Context with Color and Hue blend mode but result was wrong. Should I convert RGB to HSB, adjust HSB and convert back? 回答1: For iOS 5, you can use core image filter name CIHueAdjust. CIHueAdjust filter 回答2: I have found solution. I have simply converted color of each pixel to HSB, adjusted hue and converted back to RBG: //convert to HSB CGFloat h, s, l, a; UIColor *color = [UIColor colorWithRed:r green:g blue:b

Drawing getting pixelated in iOS

无人久伴 提交于 2019-12-13 05:08:53
问题 I am working on a drawing application, I am drawing into CGlayers , I am creating a CGlayer this way -(void)drawRect { if(self.DrawingLayer == nil) { CGFloat scale = self.contentScaleFactor; CGRect bounds = CGRectMake(0, 0, self.bounds.size.width * scale, self.bounds.size.height * scale); CGLayerRef layer = CGLayerCreateWithContext(context, bounds.size, NULL); CGContextRef layerContext = CGLayerGetContext(layer); CGContextScaleCTM(layerContext, scale, scale); self.DrawingLayer = layer; }