Wednesday, August 21, 2013

Create Grid Like xl sheet using iOS App


In this section I would like to discuss how to create gird like xl sheet using iOS Application. Well we have create it in a custom way .

  • At first we will take an image view for the header of the grid. We will set the header image in the imageView. 
  • Then we will use textBox and set the textBox programatically in effective way . 
  • We have to keep in mind that in which position we are setting the header image. According to the header image we will take the dimension and set the textBox programatically. 
  • Another thing is the grid size is dynamic according to the user choice. 
The source code is given below:

headerImageView=[[UIImageView alloc]initWithFrame:CGRectMake(055076881)];
    headerImageView.image=[UIImage imageNamed:@"R_11.png"];
    [scrollView addSubview:headerImageView];
    int x=0;
    int y=633;
    int count2=[self getCFLNo];
    NSLog(@"cflNo : %d",count2);
    
    for(int p=1 ;p<=count2;)
    {
        x=0;
        blankCellImageView=[[UIImageView alloc]initWithFrame:CGRectMake(x, y, 24050)];
        blankCellImageView.image=[UIImage imageNamed:@"blankCell.png"];
        blankCellImageView.alpha=0.8;
        [scrollView addSubview:blankCellImageView];
        x=x+110;
        // y=y+52;
        large15WTextBField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        large15WTextBField.font=font;
        large15WTextBField.backgroundColor=[UIColor whiteColor];
        large15WTextBField.layer.borderColor=[[UIColor blackColor]CGColor];
        large15WTextBField.layer.borderWidth2.0f;
        [large15WTextBField resignFirstResponder];
        large15WTextBField.delegate=self;
        // serialNumberTextField.textAlignment=UITextAlignmentCenter;
        [scrollView addSubview:large15WTextBField];
        x=x+110;
        //y=y+52;
        small15WBTextField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        small15WBTextField.font=font;
        small15WBTextField.backgroundColor=[UIColor whiteColor];
        small15WBTextField.layer.borderColor=[[UIColor blackColor]CGColor];
        small15WBTextField.layer.borderWidth2.0f;
        [small15WBTextField resignFirstResponder];
        // roomNameTextField.textAlignment=UITextAlignmentCenter;
        small15WBTextField.delegate=self;
        [scrollView addSubview:small15WBTextField];
        x=x+110;
        // y=y+52;
        large20WBTextField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        large20WBTextField.font=font;
        large20WBTextField.backgroundColor=[UIColor whiteColor];
        large20WBTextField.layer.borderColor=[[UIColor blackColor]CGColor];
        large20WBTextField.layer.borderWidth2.0f;
        [large20WBTextField resignFirstResponder];
        large20WBTextField.delegate=self;
        //  masterDeviceTextField.textAlignment=UITextAlignmentCenter;
        [scrollView addSubview:large20WBTextField];
        x=x+110;
        //y=y+52;
        large15WTextEField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        large15WTextEField.font=font;
        large15WTextEField.backgroundColor=[UIColor whiteColor];
        large15WTextEField.layer.borderColor=[[UIColor blackColor]CGColor];
        large15WTextEField.layer.borderWidth2.0f;
        [large15WTextEField resignFirstResponder];
        large15WTextEField.delegate=self;
        //   slaveDeviceTextField1.textAlignment=UITextAlignmentCenter;
        [scrollView addSubview:large15WTextEField];
        x=x+110;
        // y=y+52;
        small15WETextField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        small15WETextField.font=font;
        small15WETextField.backgroundColor=[UIColor whiteColor];
        small15WETextField.layer.borderColor=[[UIColor blackColor]CGColor];
        small15WETextField.layer.borderWidth2.0f;
        [small15WETextField resignFirstResponder];
        small15WETextField.delegate=self;
        //  slaveDeviceTextField2.textAlignment=UITextAlignmentCenter;
        [scrollView addSubview:small15WETextField];
        x=x+110;
        NSLog(@"x: %d",x);
        //  y=y+52;
        large20WETextField=[[UITextField alloc]initWithFrame:CGRectMake(x, y, 240,50)];
        large20WETextField.font=font;
        large20WETextField.backgroundColor=[UIColor whiteColor];
        large20WETextField.layer.borderColor=[[UIColor blackColor]CGColor];
        large20WETextField.layer.borderWidth2.0f;
        [large20WETextField resignFirstResponder];
        large20WETextField.delegate=self;
        //    slaveDeviceTextField3.textAlignment=UITextAlignmentCenter;
        [scrollView addSubview:large20WETextField];
        if(x==660)
        {
            y=y+52;
        }
        
        p++;
        
    }

For example the user wants to use 6 columns in the grid , then the grid will be this.....

No comments:

Post a Comment