Note that there are some explanatory texts on larger screens.

plurals
  1. POUIView: Draw at double the size
    primarykey
    data
    text
    <p>I have a UIView with a dynamically generated graphic context. Its normal size is 100x100, but it can be scaled up to 200x200, so I want its size to be actually 200x200 in order to appear nicely and not blurred however it is displayed.</p> <p>How can always draw it 200x200 in drawRect, being it displayed at a size of 100 or at a size of 200? If I'm showing it at 100x100, the rect passed to drawRect is smaller than the area I need to draw into.</p> <p>My code:</p> <pre><code> - (void) drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); // prevent the drawings to be flipped CGContextTranslateCTM(ctx, 0, rect.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); CGContextDrawImage(ctx, CGRectMake(0, 0, rect.size.width, rect.size.height), [UIImage imageNamed:@"actionBg.png"].CGImage); // generate the overlay if ([self isActive] == NO &amp;&amp; self.fullDelay != 0) { // TODO: remove fullDelay check! UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0); CGContextRef overlayCtx = UIGraphicsGetCurrentContext(); int segmentSize = (rect.size.height / [self fullDelay]); for (int i=0; i&lt;[self fullDelay]; i++) { float alpha = 0.9 - (([self fullDelay] * 0.1) - (i * 0.1)); [[UIColor colorWithRed:120.0/255.0 green:14.0/255.0 blue:14.0/255.0 alpha:alpha] setFill]; if (currentDelay &gt; i) { CGRect r = CGRectMake(0, i * segmentSize, rect.size.width, segmentSize); CGContextFillRect(overlayCtx, r); } [[UIColor colorWithRed:1 green:1 blue:1 alpha:0.3] setFill]; CGRect line = CGRectMake(0, (i * segmentSize) + segmentSize - 1 , rect.size.width, 1); CGContextFillRect(overlayCtx, line); } UIImage *overlay = UIGraphicsGetImageFromCurrentImageContext(); UIImage *overlayMasked = [TDUtilities maskImage:overlay withMask:[UIImage imageNamed:@"actionMask.png"]]; // prevent the drawings to be flipped CGContextTranslateCTM(ctx, 0, rect.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); // put the overlay CGContextSetBlendMode(ctx, kCGBlendModeMultiply); CGContextDrawImage(ctx, rect, overlayMasked.CGImage); CGContextSetBlendMode(ctx, kCGBlendModeNormal); UIGraphicsEndImageContext(); } // prevent the drawings to be flipped CGContextTranslateCTM(ctx, 0, rect.size.height); CGContextScaleCTM(ctx, 1.0, -1.0); // draw the delay symbol CGContextDrawImage(ctx, rect, [UIImage imageNamed:@"delaySymbol.png"].CGImage); CGContextSetAlpha(ctx, 0.8); // draw the symbol NSString *imgName = [K_ACTION_IMAGES objectAtIndex:[self actionType]]; CGContextDrawImage(ctx, rect, [UIImage imageNamed:imgName].CGImage); CGContextSetAlpha(ctx, 1); // draw the delay number imgName = [NSString stringWithFormat:@"%d.png", [self fullDelay]]; CGContextDrawImage(ctx, rect, [UIImage imageNamed:imgName].CGImage); // draw the priority number imgName = [NSString stringWithFormat:@"%d.png", [self actionType]]; CGContextDrawImage(ctx, CGRectMake(32, 0, rect.size.width, rect.size.height), [UIImage imageNamed:imgName].CGImage); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload