यह एक UIViewController वर्ग के रूप में बहुत Simple.I उपयोग GridView और gridView.m में निम्न कोड जोड़ने
#import "SudokuClass.h"
#import "GridView.h"
@interface GridView()
@end
@implementation GridView
-(void)createNumberButton {
int cellWidth = 34;
int cellHeight = 34;
int xSta = 7 - cellWidth;
int ySta = 50 - cellHeight;
//NSMutableDictionary *buttonTable = [[NSMutableDictionary alloc] initWithCapacity:81];
for (int i = 1; i < 10; i++) {
xSta = xSta + cellWidth;
for (int j = 1 ; j < 10; j++) {
ySta = ySta + cellHeight;
CGRect pos = CGRectMake(xSta, ySta, cellWidth, cellHeight);
UIButton *b = [SudokuClass createSudokuButtonForView:self atPos:pos
withTag:j*10+i forAction:@selector(numButtonPressed:)];
NSString *picName = @"ButtonPic.jpg";
[b setBackgroundImage:[[UIImage imageNamed:picName] stretchableImageWithLeftCapWidth:0 topCapHeight:0] forState:0];
[self.view addSubview:b];
//[numButtons addObject:b];
}
ySta = 50 - cellHeight;
}}
-(void)viewDidLoad
{
[self createNumberButton];
[super viewDidLoad];
}
@end
यहाँ
सुडोकू वर्ग है मेरी विधि
+(UIButton *)createSudokuButtonForView:(UIViewController *)view atPos:(CGRect)position withTag:(int)tag forAction:(SEL)action {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setFrame:position];
[b.titleLabel setFont:[UIFont boldSystemFontOfSize:15]];
[b setTag:tag];
[b addTarget:view action:action forControlEvents:UIControlEventTouchDown];
[b setTitle:@"" forState:0];
[b setTitleColor:[UIColor blackColor] forState:0];
//b.layer.frame = CGRectMake(xSta-1, ySta-1, 31, 31);
//[b.layer setBorderWidth:borderWidth];
b.userInteractionEnabled = YES;
return b;}
उम्मीद है कि किसी के साथ nsobject क्लास यह उपयोगी है .. :)
स्रोत
2012-10-10 13:37:33
हाय, मुझे भी इसमें इंटरैक्टिव ऑब्जेक्ट्स के साथ ग्रिड की आवश्यकता है। मैं वस्तुओं को एक स्थान से दूसरे स्थान पर शतरंज खेल में स्थानांतरित करने में सक्षम होना चाहिए। और, जब मैं ऑब्जेक्ट को स्पर्श करता हूं तो पथ को किसी अन्य रंग से दिखाया जाना चाहिए। इसलिए, मुझे लगता है कि इसके लिए मुझे ओपनजीएल और कोरग्राफिक्स चाहिए। या मुझे इसके लिए cocos2d का उपयोग करना चाहिए, धन्यवाद। –
आपको कौन सा उपयोगी लगता है? मुझे भी एक की जरूरत है! – Dinesh