drawrect

Swift / UIView / drawrect - how to get drawrect to update when required

一个人想着一个人 提交于 2019-11-27 16:26:41
问题 I'm new to learning Swift, and am trying to get an incredibly simple app to run. All I'm trying to do is get UIView.drawRect to update when I press a button . It updates/draws when the app first loads, and then nothing after that, whatever I try. I've been hitting my head against this for a couple of days, and nothing I can find helps. I created: single view application one button, linked to view controller as an action a new class, Test_View, subclassing UIView ViewController code: class

Make 2 contradictory methods work in drawRect

江枫思渺然 提交于 2019-11-27 15:44:02
I'm writing an app building elements consisting of CGPoints. I have 2 buttons: makeRectangle and makeTriangle . For building/drawing stage I use three methods for rectangle and three methods for triangle inside drawRect . I'm stuck with my code in drawRect . In if-else-statement each method swaps the building/drawing scheme for previous element every time a button pressed. If I already have built rectangle and then I click makeTriangle button, I get new triangle but my rectangle turns into triangle with one unconnected point. Is there a workaround or I shouldn't use drawRect method? Here's an

subclassed UITableViewCell - backgroundView covers up anything I do in drawRect

半世苍凉 提交于 2019-11-27 14:50:48
I'm trying to make a subclassed UITableViewCell where I draw an image in the upper right corner. I have it working perfectly - except when I set self.backgroundView, my background image covers up the image drawn in drawRect. There must be a way to be able to set a background image (and the selectedBackgroundView) without covering up what's being done in drawRect. Am I going about this the wrong way? EDIT: I've posted an example project with the problem . - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithStyle:style

Adding a drop shadow to NSString text in a drawRect: method without using UILabel

半腔热情 提交于 2019-11-27 13:38:46
问题 I'd like to add a drop shadow to text drawn using the iOS supplied NSString (UIStringDrawing) category method: - (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font minFontSize:(CGFloat)minFontSize actualFontSize:(CGFloat *)actualFontSize lineBreakMode:(UILineBreakMode)lineBreakMode baselineAdjustment:(UIBaselineAdjustment)baselineAdjustment; Clearly, there's no drop shadow option. Yes, one could use a UILabel here and get drop shadow properties to set, but that

iOS invert mask in drawRect

梦想的初衷 提交于 2019-11-27 11:36:55
问题 With the code below, I am successfully masking part of my drawing, but it's the inverse of what I want masked. This masks the inner portion of the drawing, where I would like to mask the outer portion. Is there a simple way to invert this mask? myPath below is a UIBezierPath . CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; CGMutablePathRef maskPath = CGPathCreateMutable(); CGPathAddPath(maskPath, nil, myPath.CGPath); [maskLayer setPath:maskPath]; CGPathRelease(maskPath); self.layer

Java how to paint rectangles on mouseclick

感情迁移 提交于 2019-11-27 09:52:09
As the title says, I'm having a hard time trying to draw some rectangles (filled) in JApplet. The exact goal is to have a 50x50 table and when you click on a targeted cell, to make it filled (possibly done by drawing a filled rectangle). I have done the maths about the coordinates of the starting point, but for some reason I can't draw the new rectangle in the MouseClicked method. Any suggestions? public class Main extends JApplet { public static final int DIMX = 800; public static final int DIMY = 800; public static final int ratio = 16; Graphics g; boolean drawing; public int cX; public int

iOS draw filled Circles

六眼飞鱼酱① 提交于 2019-11-27 09:51:51
问题 Not a graphics programmer here, so I'm trying to stumble through this. I'm trying to draw 9 filled circles, each a different color, each with a white border. The UIView's frame is CGRectMake (0,0,60,60). See attached image. The problem is I'm getting "flat spots" on the borders on each side. Following is my code (from the UIView subclass): - (void)drawRect:(CGRect)rect { CGRect borderRect = CGRectMake(0.0, 0.0, 60.0, 60.0); CGContextRef context = UIGraphicsGetCurrentContext();

How to fill a path with gradient in drawRect:?

霸气de小男生 提交于 2019-11-27 09:11:25
问题 filling a path with a solid color is easy enough: CGPoint aPoint; for (id pointValue in points) { aPoint = [pointValue CGPointValue]; CGContextAddLineToPoint(context, aPoint.x, aPoint.y); } [[UIColor redColor] setFill]; [[UIColor blackColor] setStroke]; CGContextDrawPath(context, kCGPathFillStroke); I'd like to draw a gradient instead of solid red, but I am having trouble. I've tried the code listed in the Question/Answer: Gradients on UIView and UILabels On iPhone which is: CAGradientLayer

UIView drawRect: Draw the inverted pixels, make a hole, a window, negative space

╄→гoц情女王★ 提交于 2019-11-27 03:40:15
问题 With the code below I am drawing a rounded rectangle. It draws a nice solid light gray filled rounded rectangle (at the size of "self"). I actually want to draw the pixel inverse of this, that is: not a solid rounded rectangle, but a window or hole in the shape of this round rectangle in a solid light gray rectangle. Is there a reverse clip method that I need to use? Or do I need to use a bezier path? Excuse if this is very basic, can't find the info though. Thanks for reading! - (void

iPhone SDK: How to trigger drawRect on UIView subclass after orientation change?

给你一囗甜甜゛ 提交于 2019-11-27 03:10:45
问题 I am subclassing a UIView and overwrite the drawRect method. I'm noticing that the view's drawrect is only being called when the view first loads. After that it is never called again. How to I make sure it gets called after an orientation change? I've tried calling setNeedsDisplay on the view before and after the rotation and that doesn't do it. 回答1: [myView setContentMode:UIViewContentModeRedraw]; You can set this in IB as well (i.e., set mode to "redraw") 回答2: This was a bug related to