Objective-C/XCode measurement question
I am building an app (desktop) that is an ad layout manager. The measurements from the Indesign template I am working with is in inches. For example, the magazine is 8x10.5 inches. So to give the user a view of the mag page I place a NSScrollView, on the main window and was using a conversion of 72 (pixels per inch) and then displaying the rulers, like so:
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 fine but the rulers comes out in inches and is a wee bit off.

Also, notice in the image there's a purple rect that starts off screen top and is off center on the view. This is a subview of the NSScroll and is suppose to represent the margins of the page. This is also off.
//make a new page element for page border开发者_开发百科s
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 am doing something wrong in my conversion/placements. Can someone correct me on this? Also, is there anyway to get the 0,0 of the ruler to line up with the x=0, y=0, coordinates of the view?
Try experimenting with the appropriate 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
Note that the units you use when setting measurement units must be registered. There are a few defaults registered or you can use your own. See the documentation of the NSRulerView class documentation for more info on the various ways you can configure ruler views.
加载中,请稍侯......
精彩评论