InterfaceBuilder
has a UIImageView Fit
. In the main controller, by reference I have an imageView
, in which there is a UIImageView
. The size is 280x280
, in the retina it should be 560Ρ
560
, but I'm doing something wrong.
A piece of code draws a chessboard, working with imageView
:
... // ΠΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·ΠΈΡΡΠ΅ΠΌ Π·Π½Π°ΡΠ΅Π½ΠΈΡ // Π Π΅ΡΠΈΠ½Π°/Π½Π΅ ΡΠ΅ΡΠΈΠ½Π° scl = [[UIScreen mainScreen] scale]; // Π Π°Π·ΠΌΠ΅ΡΡ ΠΏΠΎΠ»Ρ width = @(imageView.frame.size.width); height = width; // Π Π°Π·ΠΌΠ΅Ρ ΠΊΠ»Π΅ΡΠΊΠΈ xstep = @(10); ystep = @(10); // Π¦Π²Π΅ΡΠ° ΠΊΠ»Π΅ΡΠΎΠΊ NSArray *c1 = @[ @0 .9, @0 .9, @0 .9 ]; NSArray *c2 = @[ @0 .8, @0 .8, @0 .8 ]; // ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΊΠΎΠ½ΡΠ΅ΠΊΡΡ UIGraphicsBeginImageContextWithOptions(imageView.frame.size, NO, scl); ctx = UIGraphicsGetCurrentContext(); int len1 = @(ceil ( [width intValue] / [xstep intValue] )); int len2 = @(ceil ( [height intValue] / [ystep intValue] )); for (int xi = 0; xi < len1; xi++ ) { for (int yi = 0; yi < len2; yi++) { NSArray *c = (xi + yi) % 2 == 0 ? c1 : c2; CGContextSetRGBFillColor(ctx, [[c objectAtIndex:0] floatValue], [[c objectAtIndex:1] floatValue], [[c objectAtIndex:2] floatValue], 1.0); CGContextFillRect(ctx, CGRectMake( xi*[xstep intValue], yi*[ystep intValue], [xstep intValue], [ystep intValue])); } } // ΠΠ°ΠΏΠΈΡΡΠ²Π°Π΅ΠΌ ΡΡΠΎΡΠΌΠΈΡΠΎΠ²Π°Π½Π½ΡΠΉ ΡΠΈΡΡΠ½ΠΎΠΊ Π² Π½Π°Ρ UIImageView CGContextStrokePath(ctx); imageView.image = UIGraphicsGetImageFromCurrentImageContext();
As a result, the chessboard is drawn correctly 28x28
cells in the usual mode, but on retina
there are also 28Ρ
28
, and it should be 56Ρ
56
.
0
as the last parameter inUIGraphicsBeginImageContextWithOptions()
- automatic multiplier determination? - VioLet