drawrect

Black background in UIView?

五迷三道 提交于 2019-12-05 03:11:35
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 (self = [super initWithCoder:aDecoder]) { [self setMultipleTouchEnabled:NO]; [self setBackgroundColor:

Optimize CGContextDrawRadialGradient in drawRect:

空扰寡人 提交于 2019-12-05 02:54:32
问题 In my iPad app, I have a UITableView that alloc/inits a UIView subclass every time a new cell is selected. I've overridden drawRect: in this UIView to draw a radial gradient and it works fine, but performance is suffering - when a cell is tapped, the UIView takes substantially longer to draw a gradient programmatically as opposed to using a .png for the background. Is there any way to "cache" my drawRect: method or the gradient it generates to improve performance? I'd rather use drawRect:

UITableViewCell drawInRect iOS7

我们两清 提交于 2019-12-05 02:07:34
问题 Hi I am trying to draw strings in my UITableViewCell in iOS 7 with the following code -(void)drawRect:(CGRect)rect{ [super drawRect:rect]; CGRect playerNameRect = CGRectMake(0, kCellY, kPlayerNameSpace, kCellHeight); NSDictionary*dictonary = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor hmDarkGreyColor], NSForegroundColorAttributeName, kFont, NSFontAttributeName, nil]; [self.playerName drawInRect:playerNameRect withAttributes:dictonary]; } However I can not get anything to appear...

On iOS, setNeedsDisplay really doesn't cause drawRect to be called… unless CALayer's display or drawInContext finally calls drawRect?

可紊 提交于 2019-12-04 13:54:18
问题 I don't really understand how CALayer's display and drawInContext relate to drawRect in the view. If I have an NSTimer that sets the [self.view setNeedsDisplay] every 1 second, then drawRect is called every 1 second, as shown by an NSLog statement inside of drawRect . But if I subclass a CALayer and use that for the view, if I make the display method empty, then now drawRect is never called. Update: But display is called every 1 second, as shown by an NSLog statement. If I remove that empty

Qt drawRect in background

走远了吗. 提交于 2019-12-04 10:12:45
I want to paint the background of a slider. I tried this but the color covers up the whole slider. This is in an inherited class of QSlider void paintEvent(QPaintEvent *e) { QPainter painter(this); painter.begin(this); painter.setBrush(/*not important*/); // This covers up the control. How do I make it so the color is in // the background and the control is still visible? painter.drawRect(rect()); painter.end(); } To set the background of a widget you could set the style sheet: theSlider->setStyleSheet("QSlider { background-color: green; }"); The following will set the background of the widget

How can I fill a rect with an alpha color using CoreGraphics?

落花浮王杯 提交于 2019-12-04 10:01:54
In my drawRect method, I am drawing a PNG image. On top of that, I want to draw a rect with a 20% alpha color, like this: [[UIColor colorWithWhite:0.0 alpha:0.2] set]; UIRectFill(rect); The problem is, that the alpha property seems to get ignored. No alpha is applied at all, just a black rectangle is drawn. How can I fix this? Thanks in advance! Use CGContextSetBlendMode() before you draw the rect. Set your view background color to transparent… It should work. 来源: https://stackoverflow.com/questions/2935608/how-can-i-fill-a-rect-with-an-alpha-color-using-coregraphics

UIView with CATransform3D inside a UITableViewCell = Choppy Scrolling

半世苍凉 提交于 2019-12-04 09:32:24
I'm using a custom UITableViewCell , into which I am placing a subclassed UIView (within contentView , natch). The UIView in question displays a directional arrow and two lines of supporting text. The arrow is displayed by means of a layer with a background color and an arrow-shaped mask. The background color changes to one of two possibilities depending on the direction the arrow is pointing. The view receives a NSNotification whenever it needs to update the arrow (based on, but not identical to, the current heading - each cell and view is different). When it receives notice, the view calls a

A red rectangle drawn on 2D texture disappears right after being drawn

喜夏-厌秋 提交于 2019-12-04 05:49:19
问题 following my another question, I have provided the code that draws the rectangle as follows: void COpenGLControl::DrawRectangleOnTopOfTexture() { wglMakeCurrent(hdc, hrc); glPushAttrib(GL_ENABLE_BIT|GL_CURRENT_BIT); glDisable(target); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_LINE_LOOP); glVertex2f(RectangleToDraw.at(0),RectangleToDraw.at(1)); glVertex2f(RectangleToDraw.at(0),RectangleToDraw.at(3)); glVertex2f(RectangleToDraw.at(2),RectangleToDraw.at(3)); glVertex2f(RectangleToDraw.at(2)

Any possible way to call drawRect from a UIViewcontroller class?

偶尔善良 提交于 2019-12-04 05:25:15
问题 I have a UIViewController class called AppController.h , AppController.m . I have thousands of lines of code in there, and that is the only reason why I didn't test this before I asked it. Is there any possible way to use drawRect in a UIViewController ? that way I wouldn't have to make more delegates and methods and callbacks. I should have started off using drawRect to handle my drawing code, but I didn't, and there's severe lag with core graphics on the iPad. So, please let me know if

UIView overriding drawRect causes view not to obey masksToBounds

不羁岁月 提交于 2019-12-04 04:53:34
I am trying to override the drawRect: method of UIView in my custom view. However, my view has a border radius defined as: sub = [[[NSBundle mainBundle] loadNibNamed:@"ProfileView" owner:self options:nil] objectAtIndex:0]; [self addSubview:sub]; [sub setUserInteractionEnabled:YES]; [self setUserInteractionEnabled:YES]; CALayer *layer = sub.layer; layer.masksToBounds = YES; layer.borderWidth = 5.0; layer.borderColor = [UIColor whiteColor].CGColor; layer.cornerRadius = 30.0; This works perfectly and places a nice border with a border radius around my view (don't mind the diagonal/straight white