用lable画表格

来源:互联网 发布:思维导图用什么软件 编辑:程序博客网 时间:2024/05/16 05:12

 CGRect viewRect=self.view.frame;

   //画基本信息

   NSDictionary *basicInformDic=(NSDictionary *)[[[dicobjectForKey:@"returnResult"]objectForKey:@"dtBasicInform"]objectAtIndex:0];

   NSDictionary *wageInformDic=(NSDictionary *)[[[dicobjectForKey:@"returnResult"]objectForKey:@"dtWageInform"]objectAtIndex:0];

   CGRect basicInformRect=CGRectMake(106,20, viewRect.size.width-106,200);

   NSArray* basicLabelArray=[NSArrayarrayWithObjects:@"姓名",@"出生日期",@"文化程度",@"取得时间",

                        @"",@"籍贯",@"毕业时间",@"政治面貌",

                        @"民族",@"身份证号",@"学位",@"加入时间",

                        nil];

    [selfdrawGrid:basicInformDic andBakDic:wageInformDic andWidthLabelNumber:3andHeightLabelNumber:4andRect:basicInformRect andLabelArray:basicLabelArray];

   //画工资信息

   CGRect wageInformRect=CGRectMake(20,200+20, viewRect.size.width-20,300);

   NSArray* wageLabelArray=[NSArrayarrayWithObjects:@"单位",@"职务级别",@"岗位工资标准",

                  @"员工编号",@"职称",@"合同编号",

                  @"工作岗位",@"取得资格日期",@"合同类型",

                  @"工作时间",@"公子序列",@"开始日期",

                  @"工龄起算日",@"岗级",@"结束日期",

                  @"首次加入中石油日期",@"档次",

                  nil];

    [selfdrawGrid:basicInformDic andBakDic:wageInformDicandWidthLabelNumber:2andHeightLabelNumber:9andRect:wageInformRect andLabelArray:wageLabelArray];









-(void)drawGrid:(NSDictionary *)informDic andBakDic:(NSDictionary *)informDicBak andWidthLabelNumber:(float )widthLabelNumber andHeightLabelNumber:(float )heightLabelNumber andRect:(CGRect )informRect  andLabelArray:(NSArray *)labelArray

{

   float labelLength=informRect.size.width/widthLabelNumber/2;

   float labelHeitht=informRect.size.height/heightLabelNumber;

   for (NSUInteger i=0; i<heightLabelNumber; i++) 

    {

       for (NSUInteger j=0; j<widthLabelNumber; j++) {

           if (i*widthLabelNumber+j>[labelArray count]-1) {

               continue;

            }

            

           UILabel *lKey = [[UILabelalloc] initWithFrame:CGRectMake(informRect.origin.x+j*labelLength*2

                                                                      informRect.origin.y+i*labelHeitht, 

                                                                      labelLength, labelHeitht)];

            lKey.font = [UIFontsystemFontOfSize:14.0f];

            lKey.text = [NSStringstringWithFormat:@"%@:",[labelArrayobjectAtIndex:i*widthLabelNumber+j]];  

            lKey.backgroundColor = [UIColorclearColor];

            lKey.textColor = [UIColorblueColor];

            lKey.textAlignment =UITextAlignmentRight;

            [self.viewaddSubview:lKey];

           //value

           UILabel *lValue = [[UILabelalloc] initWithFrame:CGRectMake(informRect.origin.x+j*labelLength*2+labelLength,

                                                                        informRect.origin.y+i*labelHeitht, 

                                                                        labelLength, labelHeitht)];

            lValue.font = [UIFontsystemFontOfSize:14.0f];

            lValue.text =  [informDicobjectForKey: [labelArray objectAtIndex:i*widthLabelNumber+j]];

            lValue.backgroundColor = [UIColorclearColor];

            lValue.textColor =  [UIColorblackColor];

            lValue.textAlignment =UITextAlignmentLeft;

            [self.viewaddSubview:lValue];

        }

    }

}