drawrect

UIScrollView draw ruler using drawRect

狂风中的少年 提交于 2021-01-29 10:48:49
问题 I am trying to draw a ruler on top of UIScrollView. The way I do it is by adding a custom view called RulerView. I add this rulerView to superview of scrollView setting its frame to be same as frame of scrollView. I then do custom drawing to draw lines as scrollView scrolls. But the drawing is not smooth, it stutters as I scroll and the end or begin line suddenly appears/disappears. What's wrong in my drawRect? class RulerView: UIView { public var contentOffset = CGFloat(0) { didSet { self

drawRect Invalid Context

扶醉桌前 提交于 2020-03-23 08:03:40
问题 Trying to draw a graph in UIView from values pulled down from a server. I have a block that is successfully pulling the start/end points (I did have to add the delay to make sure the array had the values before commencing. I've tried moving the CGContextRef both inside and outside the dispatch but I still get 'Invalid Context'. I have tried adding [self setNeedsDisplay]; at various places without luck. Here's the code: - (void)drawRect:(CGRect)rect { // Drawing code // Array - accepts values

drawRect Invalid Context

試著忘記壹切 提交于 2020-03-23 08:02:32
问题 Trying to draw a graph in UIView from values pulled down from a server. I have a block that is successfully pulling the start/end points (I did have to add the delay to make sure the array had the values before commencing. I've tried moving the CGContextRef both inside and outside the dispatch but I still get 'Invalid Context'. I have tried adding [self setNeedsDisplay]; at various places without luck. Here's the code: - (void)drawRect:(CGRect)rect { // Drawing code // Array - accepts values

Continuous drawing in CGContext with drawRect

放肆的年华 提交于 2020-02-07 06:56:20
问题 My question might be answered somewhere but I just couldn't find solution after a long research. I need to draw visually shapes (curves, lines, rectangles etc.) on iPhone one on top of the previous. I did that using CGContext to draw over an image and it's working fine. However in my app the drawing view resizes on device rotation and the lines become blurred because of the different image size. That's why I subclassed UIView and to call setNeedsDisplay from touchesMoved and touchesEnded . In

Why is drawRect leaving parts of image?

ぐ巨炮叔叔 提交于 2020-01-23 12:59:08
问题 Here's my case: I have a table which contains a list of restaurants, each entry shows the results of inspections over time on a scorebar that is drawn using drawRect. When the user scrolls the table down and then up, so that scorebars with yellow and red squares are shown, previous scorebars pick up those squares. Dates are also drawn into previous scorebars. My problem lies in getting rid if the old squares. Shouldn't they be erased each time drawRect is called? I've placed three images

Black background in UIView?

巧了我就是萌 提交于 2020-01-23 05:26:09
问题 I followed a tutorial online to draw in a subclassed UIView. The tutorial showed a UIView with a white background, I fixed this by simply changing the super's bg color. The problem is, when touches end, the background does not remain clear. I have no idea. I simply tried setting the fill color to [uicolor clearcolor]; unsuccessfully. Here is the code I am using: @implementation CachedLIView { UIBezierPath *path; UIImage *incrementalImage; // (1) } - (id)initWithCoder:(NSCoder *)aDecoder { if

Swift 3: Drawing a rectangle

回眸只為那壹抹淺笑 提交于 2020-01-23 05:04:05
问题 I'm 3 days new to swift, and I'm trying to figure out how to draw a rectangle. I'm too new to the language to know the classes to extend and the methods to override, and I've looked around for sample code, but nothing seems to work (which I'm attributing to my use of swift 3). What I'm trying now is: import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let k = Draw(frame: CGRect( origin: CGPoint(x: 50, y: 50), size: CGSize(width: 100, height:

Swift 3: Drawing a rectangle

泄露秘密 提交于 2020-01-23 05:02:58
问题 I'm 3 days new to swift, and I'm trying to figure out how to draw a rectangle. I'm too new to the language to know the classes to extend and the methods to override, and I've looked around for sample code, but nothing seems to work (which I'm attributing to my use of swift 3). What I'm trying now is: import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let k = Draw(frame: CGRect( origin: CGPoint(x: 50, y: 50), size: CGSize(width: 100, height:

UIView class properties seemingly disappear when I call drawRect:

好久不见. 提交于 2020-01-17 04:44:05
问题 I am coding an objective-c project with xcode. I have two important files that are being used: a viewcontroller, and a view. My view is class "PlayingCardView", my viewcontroller is class: "PlayingCardGameViewController". Here is what PlayingCardView.h looks like: #import <UIKit/UIKit.h> @interface PlayingCardView : UIView @property (nonatomic) NSUInteger rank; @property (strong, nonatomic) NSString *suit; @property (nonatomic) BOOL faceUp; @end Here is the important code from PlayingCardView

getting the text up-side down in core graphic

*爱你&永不变心* 提交于 2020-01-16 19:57:48
问题 I am drawing a text in core graphic by following - (void)drawRect:(CGRect)rect { CGContextTranslateCTM(context, 20, 150); CGContextScaleCTM(context, 1, 1); // Draw the text using the MyDrawText function myDrawText(context, viewBounds); } void myDrawText (CGContextRef myContext, CGRect contextRect) { CGFloat w, h; w = contextRect.size.width; h = contextRect.size.height; CGAffineTransform myTextTransform; CGContextSelectFont (myContext, "Helvetica-Bold", h/12, kCGEncodingMacRoman);