2011-12-26 2 views
0

나는 범용 (iphone/ipad) 응용 프로그램을 개발 중입니다. 나는이 응용 프로그램에서 uitableview를 사용하고 있습니다. 표 셀은 코드를 사용하여 그립니다. 이제 문제는 단일 코드에서만 iPad 또는 iPhone에 맞을 수 있다는 것입니다. 코드를 한 번만 입력하면됩니다. universal uitableview 스트레칭 문제

는 I 2 시간 코딩해야하고 장치를 확인하는 조건을 넣어해야이를 위해

이있다 ..시오는 배경 이미지 uilable 등의 프레임을 설정하는 아이폰 1 의미와 다른 내게 쓰레기와 바보 같은 직업을 찾고. 단일 코드로이 목표를 달성 할 수있는 방법이 있습니까? 내 코드는 다음과 같습니다. xcode 4.2를 사용 중입니다. ARC

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UIFont *fontName=[UIFont fontWithName:@"HelveticaNeue LT 57 Cn" size:18.0f]; 
    UIFont *fontTitle=[UIFont fontWithName:@"HelveticaNeue LT 57 Cn" size:12.0f]; 
    UIFont *grayLight=[UIFont systemFontOfSize:12.0f]; 
    //UIFont *fontBold=[UIFont boldSystemFontOfSize:[UIFont systemFontSize]]; 

    UITableViewCell *cell = [[UITableViewCell alloc] init]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    NSMutableDictionary *dic=[arrEmails objectAtIndex:indexPath.row]; 
    //NSLog(@"%@",dic); 
    int tot=4; 
    NSString *imageName=[NSString stringWithFormat:@"inbox_list%d",(indexPath.row%tot)+1]; 

    UIImageView *imgBg=[[UIImageView alloc] initWithFrame:CGRectMake(-30, 10, 303, 70)]; 
    [imgBg setImage:[UIImage imageNamed:imageName]]; 
    [cell.contentView addSubview:imgBg]; 
    NSString *name=nameDisplayType==1 ? [[dic valueForKey:@"firstName"] stringByAppendingFormat:@" %@", [dic valueForKey:@"lastName"]] : [[dic valueForKey:@"lastName"] stringByAppendingFormat:@" %@", [dic valueForKey:@"firstName"]]; 

    UILabel *lblFirstName=[[UILabel alloc] initWithFrame:CGRectMake(30 ,15,150,20)]; 
    [lblFirstName setText:name]; 
    [lblFirstName setBackgroundColor:[UIColor clearColor]]; 
    [lblFirstName setTextColor:UIColorFromRedGreenBlue(162, 23, 25)]; 
    [lblFirstName setTextAlignment:UITextAlignmentLeft]; 
    [lblFirstName setFont:fontName]; 
    [lblFirstName setBackgroundColor:[UIColor clearColor]]; 
    [cell.contentView addSubview:lblFirstName]; 


    UILabel *lblEmailId=[[UILabel alloc] initWithFrame:CGRectMake(30,28,200,20)]; 
    [lblEmailId setText:[dic valueForKey:@"emailId"]]; 
    [lblEmailId setBackgroundColor:[UIColor clearColor]]; 
    [lblEmailId setTextAlignment:UITextAlignmentLeft]; 
    [lblEmailId setFont:grayLight]; 
    [lblEmailId setTextColor:[UIColor grayColor]]; 
    [lblEmailId setBackgroundColor:[UIColor clearColor]]; 
    [cell.contentView addSubview:lblEmailId]; 




    NSDateFormatter *formatter=[[NSDateFormatter alloc] init]; 
    [formatter setDateFormat:@"yyyy-MM-dd"]; 
    NSDate *date=[formatter dateFromString:[dic valueForKey:@"date"]]; 
    [formatter setDateFormat:@"dd MMM, yyyy"]; 
    NSString *formattedDate=[formatter stringFromDate:date]; 
    //NSLog(@"%@ formated:%@",[dic valueForKey:@"date"],formattedDate); 

    UILabel *lblDate=[[UILabel alloc] initWithFrame:CGRectMake(190,15,100,20)]; 
    [lblDate setText:formattedDate]; 
    [lblDate setBackgroundColor:[UIColor clearColor]]; 
    [lblDate setTextAlignment:UITextAlignmentLeft]; 
    [lblDate setFont:grayLight]; 
    [lblDate setTextColor:[UIColor blackColor]]; 
    [cell.contentView addSubview:lblDate]; 


    UILabel *lblTitle=[[UILabel alloc] initWithFrame:CGRectMake(20,53,200,20)]; 
    [lblTitle setText:[dic valueForKey:@"title"]]; 
    [lblTitle setBackgroundColor:[UIColor clearColor]]; 
    [lblTitle setTextAlignment:UITextAlignmentLeft]; 
    [lblTitle setFont:fontTitle]; 
    [lblTitle setTextColor:[UIColor blackColor]]; 
    [cell.contentView addSubview:lblTitle]; 

    UIButton *btnViewGift=[[UIButton alloc] initWithFrame:CGRectMake(235, 55, 20, 20)]; 
    [btnViewGift addTarget:self action:@selector(btnViewGiftPressed:) forControlEvents:UIControlEventTouchUpInside]; 
    [btnViewGift setTag:indexPath.row]; 
    [cell.contentView addSubview:btnViewGift]; 


    cell.accessoryType = UITableViewCellAccessoryNone; 


    return cell; 
} 

도와 주시겠습니까? 미리 감사드립니다.

답변

0

프레임으로 하드 코드 된 악기를 전달하는 대신보기의 프레임 및 경계 속성을 사용하여 프레임을 동적으로 결정할 수 있습니다. 그러나 각 UI 요소를 관리해야합니다.

+1

좋아요 try -UILabel * lblFirstName = [[UILabel 할당] initWithFrame : CGRectMake (self.view.frame.origin.x + someOffset, self.view.frame.origin.y + someOtherOffset, self.view.frame.size .width/someWidthOffset, self.view.frame.size.height/someHeighOffset)]; -> 프레임을 결정합니다. – rishi