drawrect

How to draw an UIImage or directly in -drawRect:?

杀马特。学长 韩版系。学妹 提交于 2019-12-28 05:16:27
问题 I have an UIImage which I want to draw on a UIView . But instead of creating an UIImageView and adding this as a subview, I want to overwrite -drawRect: and draw my UIView directly. For example, my code looks like: - (void)drawRect:(CGRect)rect { CGContextRef myContext = UIGraphicsGetCurrentContext(); UIImage *img = [UIImage imageNamed:@"foo.png"]; // how to draw the directly into the view now? } 回答1: Call [img drawInRect:rect]; . 回答2: BTW, you shouldn't load the image file in the drawRect

CALayer and drawRect

£可爱£侵袭症+ 提交于 2019-12-24 10:27:42
问题 I'm completely new to Core Animation, CALayer and all this stuff, so bear with me. I have a custom NSTextField using as a Label. I would want the content to animate it's position, so the whole string get's visible if it's too long for the Labels width. Now, the animation itself is working fine. I've implemented this with CABasicAnimation: - (void)awakeFromNib { CALayer *newLayer = [CALayer layer]; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; [animation

Is drawrect more efficient for coregraphcs drawing than using core graphics in touches moved?

走远了吗. 提交于 2019-12-24 08:08:52
问题 My whole app uses touchesMoved for drawing (Coregraphics). Should I be calling [self setNeedsDisplay] from within touchesMoved instead of performing the drawing code in there? Would that stop some lag that I am experiencing? The only reason I didn't try this before posting is because it is going to take me a few hours to convert all drawing to within drawRect and I wanted to know if it would be more would efficient than drawing in touchesMoved ? 回答1: Yes. You should always keep your drawing

UIScrollView redrawing content while scrolling?

一笑奈何 提交于 2019-12-24 02:06:22
问题 I know there is a property or method that makes the scrollview/uiview call drawRect: method while is scrolling. By default is disabled because of performance reasons but I need to enable it. I cannot remember the name of the method hence I cannot look for it, anyone who knows what I am looking for? Thanks in advance 回答1: I'ld suggest to use the scrollViewDidScroll:-method and then redraw the view. - (void)scrollViewDidScroll:(UIScrollView *)scrollView { [someView setNeedsDisplay]; } 来源: https

Is there any performance loss when repeatedly calling UIGraphicsGetCurrentContext

烈酒焚心 提交于 2019-12-23 19:00:21
问题 I'm building a UIView with a custom drawRect function. This is a fairly complex view, with a number of different items that need to be drawn. I've basically broken it down into one function per item that needs to be drawn. What I'm wondering is should I pass my CGContextRef , obtained from UIGraphicsGetCurrentContext() , as a parameter to each function, or can I just call it at the start of each function? The latter option looks neater to me, but I am wondering if there is much of a

Navigation Bar customization in ios4 doesnt work in ios5

杀马特。学长 韩版系。学妹 提交于 2019-12-23 04:45:06
问题 i know that this question looks the same as other around here, but none of them say anything about incompatibility between ios4 and ios5. In my app i want to customize the pattern of the navigation Bar, but my deployment target is ios4, so i am using the code bellow above the implementation of the appDelegate.m to do this: @implementation UINavigationBar (CustomImage) - (void)drawRect:(CGRect)rect { UIColor *color = [UIColor blackColor]; UIImage *image = [UIImage imageNamed: @"nav_bar.png"];

Empty drawRect implementation causes memory warning

不羁的心 提交于 2019-12-22 17:42:02
问题 I have a UIView on which I draw a UIBezierPath by finger. When I rezoom the view (say after a path is drawn) a redraw function is triggered, which rescales the BezierPath: - (void)redrawPathsWithScale:(float)scale { [_path applyTransform:CGAffineTransformMakeScale(scale, scale)]; [self setNeedsDisplay]; } setNeedsDisplay causes drawRect to get called. Now every time I zoom in to a absolute scale somewhere near x6 I immediately get a memory warning, and the App crashes. My drawRect method

Resize line from endpoints

不问归期 提交于 2019-12-22 13:49:19
问题 I am drawing annotations on a view. The line annotation is causing a problem; I have a parent class of Shape (extended from UIView). All the annotations are subclass of shape. In each annotation class i have override the drawRect method. DrawingCanvas class (extended from UIView and is a subview of my viewController's parent view) handles the pan gesture. Here is a piece of code -(void) panGestureRecognizer: (UIPanGestureRecognizer *) panGesture { static CGPoint initialPoint; CGPoint

Can I draw shapes like circle,rectangle,line etc outside drawRect method

北慕城南 提交于 2019-12-22 09:05:33
问题 Can I draw shapes like circle, rectangle, line etc outside drawRect method using CGContextRef contextRef = UIGraphicsGetCurrentContext(); or is it mandatory to use it inside drawRect only. Please help me, let me know how can I draw shapes outside drawRect method. Actually i want to go on plotting dots on touchesMoved event. This is my code for drawing a dot. CGContextRef contextRef = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(contextRef, 0, 255, 0, 1); CGContextFillEllipseInRect

Not able to include undo/redo with smooth free hand drawing

若如初见. 提交于 2019-12-21 18:49:31
问题 Struggling with issue since many days. Hope i can get an answer here. i have used this link to smoothen my free hand drawing. In this code i was able to set line width and color but i am finding it much difficult when i try to include undo/redo feauture in it using this link which is working fine on undo redo but its free hand dreawing is not smooth. After some research and coding i am to know that its the cathing of drawing which is i think preventing the undo/redo. In the first link there