Objective-C / Xcode Measurement Question

I am creating an application (desktop) that is an ad layout manager. The dimensions from the Indesign template I'm working with are in inches. For example, a magazine measuring 8x10.5 inches. Therefore, to give the user an idea of ​​the mag page, I place the NSScrollView in the main window and use the conversion 72 (pixels per inch) and then display the ruler, for example:

displayPageRect=NSMakeRect(400.0, 70.0,72*8.125,72*10.5); displayPage = [[NSScrollView alloc] initWithFrame:displayPageRect]; //set up the rulers display [displayPage setRulersVisible:YES]; [displayPage setHasVerticalRuler:YES]; [displayPage setHasHorizontalRuler:YES]; //set up border color and width [displayPage setBorderType:NSLineBorder]; //display the displayPage on the screen [[mainWin contentView] addSubview:displayPage]; 

this works great, but the rulers come out in inches and are a bit bitten.

enter image description here

Also, note that there is a purple rectangle in the image that starts from the top of the screen and is out of center on the screen. This is an NSScroll routine and is supposed to represent page fields. This does not work either.

  //make a new page element for page borders PageElements* pageBorders = [PageElements new]; NSColor* borderColor = [NSColor purpleColor]; [pageBorders setColor:borderColor]; [pageBorders initWithFrame:NSMakeRect(72*.313, 72*.375, 72*7.499, 72*9.875)]; [[displayPage contentView] addSubview:pageBorders]; 

Obviously I'm doing something wrong in my conversions / placements. Can someone correct me on this? In addition, is there anyway to get the 0,0 ruler of the ruler with x = 0, y = 0, the coordinates of the form?

+4
source share
1 answer

Try experimenting with the corresponding properties of the associated NSRulerView:

 NSRulerView *hRuler = [displayPage horizontalRulerView]; [hRuler setMeasurementUnits:@"Points"]; // User whatever registered units you want here [hRuler setOriginOffset:5.0]; // Experiment with this number to see way works for you 

Please note that the blocks that you use when setting up the units of measure must be registered. Several registered by default are registered or you can use your own. See the documentation for the NSRulerView class documentation for more information on the different ways that ruler views are displayed.

+3
source

All Articles