2016-06-28 1 views
0

だから私は次のコードthatsボックスを描画する責任がPanelWidthとPanelheightのユーザーからのテイク入力をボックスごとに2色で描画します。私は行の1,2,3,4,5,6だけでなく、列のA1、B1、C1のように行を印刷することができるようにするにはどうすればよいですか? Objective Cのプリントしたい数のボックスにカウンターカウンターカウンターを印刷したい。 OS X ObjectiveC

で、これはこのコードprints nowは、これは私がこれを行うには、いくつかの方法がありますprint

//screen drawing 

for (int r=0; r < 2*row; r++) { 
    long int positionVer = (panelHeight*r); 

    for (int i=0; i < 2*col; i++) { 
     long int positionHor = (panelWidth*i); 

     NSRect col1= NSMakeRect(positionHor,positionVer, panelWidth, panelHeight); 

     if (_bgEnable) { 
      if((r+i) %2) 
      { 
       [rectColor2 set]; 
      } 
      else { 
       [rectColor set]; 
      } 

     } 


     else{ 
      [[NSColor colorWithCalibratedWhite:0.0 alpha:0.0] setFill]; 
      NSRectFillUsingOperation(col1, NSCompositeSourceAtop); 
     } 

     NSRectFill (col1); 

     if (_BoarderEnable) { 
     [boarderColor set]; 
     NSFrameRectWithWidth (col1, _boarderWidth); 
     } 
    } 
} 

答えて

0

に望むものは何かということです。ここに1つあります。これは、カスタムビューを使用して図面を作成します(ビューを作成して値を割り当てるのはあなた次第です)。図面はボトムアップから番号付けが正しく行われるように、合計行から始めて現在の行を引く必要があります(使いやすさのために、列番号に1を加えてください)。 ASCII文字はシーケンシャルなので、65(A)から始まりそこからインクリメントすることができます。また、テキストの属性を更新し、ユーザが必要に応じてさらにカスタマイズできるようにすることもできます。私はいくつかの最適化を行うことができます(またはこれを全体的に行うにはより良い方法です)が、これはあなたを動かすはずです。

@interface BoxView : NSView 
@property (assign) NSInteger columnCount; 
@property (assign) NSInteger rowCount; 
@property (assign) CGFloat width; 
@property (assign) CGFloat height; 
@property (strong) NSColor *c0; 
@property (strong) NSColor *c1; 
@property (assign) BOOL drawBorder; 
@end 

@implementation BoxView 

- (void)drawRect:(NSRect)rect { 
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: 
           [NSFont labelFontOfSize:12.0], NSFontAttributeName, 
           [NSColor whiteColor], NSForegroundColorAttributeName, 
           nil]; 
    CGFloat x = 0.0, y = 0.0; 
    BOOL useColor0 = YES; 
    for (NSInteger r = 0; r < self.rowCount; r++) { 
     for (NSInteger c = 0; c < self.columnCount; c++) { 
      NSRect box = NSMakeRect(x, y, self.width, self.height); 
      NSBezierPath *path = [NSBezierPath bezierPathWithRect:box]; 
      [(useColor0 ? self.c0 : self.c1) set]; 
      [path fill]; 
      if (self.drawBorder) { 
       [[NSColor blackColor] setStroke]; 
       [path stroke]; 
      } 
      NSString *arrow = nil; 
      if (r == 0) { 
       if (self.rowCount % 2) { 
        if (c == (self.columnCount - 1)) arrow = @"∅"; 
       } else if (c == 0) { 
        arrow = @"∅"; 
       } 
      } 
      if (!arrow) { 
       if ((self.rowCount - r) % 2) { 
        arrow = ((c == (self.columnCount - 1)) ? @"↓" : @"→"); 
       } else { 
        arrow = ((c == 0) ? @"↓" : @"←"); 
       } 
      } 
      NSString *label = [NSString stringWithFormat:@"%c%ld %@", (char)(65 + c), (self.rowCount - r), arrow]; 
      [label drawAtPoint:NSMakePoint((x + 5.0), (y + self.height - 16.0)) withAttributes:attributes]; 
      x += self.width; 
      useColor0 = !useColor0; 
     } 
     x = 0.0; 
     y += self.height; 
     useColor0 = (r % 2); 
    } 
} 

@end 

あなたはここでデモアプリケーションをダウンロードすることができます:BoxesDemo.zip

+0

は、このコードにどうもありがとうございます!!私は本当にこの長さに行くあなたの助けに感謝します。あなたが気にしないなら、私はrit3sh7でgmailで私に電子メールを送ってください気にしないなら、あなたとチャットしたいですか? – ritesh

関連する問題