3

我正在一个项目中工作,其中标签和图像的位置根据我单击的按钮对齐。

位置存储在一个数组中,我像下面的代码一样分配了位置

-(IBAction)templateButtonClicked:(id)sender {

UIButton *button=(UIButton*)sender;
NSLog(@"button tag is %d",button.tag);

if (button.tag==1) {


    CGPoint companyNameLblpos;
    CGRect companyNameLblSize;
companyNameLblpos.x=[[cnXArr objectAtIndex:j]floatValue];
companyNameLblpos.y=[[cnYArr objectAtIndex:j] floatValue];
    //NSLog(@"cnXArr and cnYArr is %0.2f and %0.2f",companyNameLblpos.x,companyNameLblpos.y);
companyNameLblSize.size.width=[[cnWArr objectAtIndex:j] floatValue];
companyNameLblSize.size.height=[[cnHArr objectAtIndex:j] floatValue];
    companyNameLbl.center=companyNameLblpos;
    companyNameLbl.bounds=companyNameLblSize;



    CGPoint yourNameLblPos;
    CGRect yourNameLblSize;
yourNameLblPos.x=[[ynXArr objectAtIndex:j] floatValue];
yourNameLblPos.y=[[ynYArr objectAtIndex:j] floatValue];
yourNameLblSize.size.width=[[ynWArr objectAtIndex:j] floatValue];
yourNameLblSize.size.height=[[ynHArr objectAtIndex:j] floatValue];
    yourNameLbl.center=yourNameLblPos;
    yourNameLbl.bounds=yourNameLblSize;
    yourNameLbl.textColor=[UIColor blackColor];

    CGPoint designationLblPos;
    CGRect designationLblSize;
designationLblPos.x=[[dXArr objectAtIndex:j] floatValue];
designationLblPos.y=[[dYArr objectAtIndex:j] floatValue];
designationLblSize.size.width=[[dWArr objectAtIndex:j] floatValue];
designationLblSize.size.height=[[dHArr objectAtIndex:j] floatValue];
    designationLbl.center=designationLblPos;
    designationLbl.bounds=designationLblSize;


    CGPoint addrLine1LeftLblPos;
    CGRect addrLine1LeftLblSize;
addrLine1LeftLblPos.x=[[ad1XArr objectAtIndex:j] floatValue];
addrLine1LeftLblPos.y=[[ad1YArr objectAtIndex:j] floatValue];
addrLine1LeftLblSize.size.width=[[ad1WArr objectAtIndex:j] floatValue];
addrLine1LeftLblSize.size.height=[[ad1HArr objectAtIndex:j] floatValue];
    addrLine1LeftLbl.center=addrLine1LeftLblPos;
    addrLine1LeftLbl.bounds=addrLine1LeftLblSize;



    CGPoint addrLine2LeftLblPos;
    CGRect addrLine2LeftLblSize;
addrLine2LeftLblPos.x=[[ad2XArr objectAtIndex:j] floatValue];
addrLine2LeftLblPos.y=[[ad2YArr objectAtIndex:j] floatValue];
addrLine2LeftLblSize.size.width=[[ad2WArr objectAtIndex:j] floatValue];
addrLine2LeftLblSize.size.height=[[ad2HArr objectAtIndex:j] floatValue];
    addrLine2LeftLbl.center=addrLine2LeftLblPos;
    addrLine2LeftLbl.bounds=addrLine2LeftLblSize;
    addrLine2LeftLbl.textColor=[UIColor blackColor];


    CGPoint telNoLblPos;
    CGRect telNoLblSize;
telNoLblPos.x=[[phXArr objectAtIndex:j] floatValue];
telNoLblPos.y=[[phYArr objectAtIndex:j] floatValue];
telNoLblSize.size.width=[[pWArr objectAtIndex:j] floatValue];
telNoLblSize.size.height=[[pHArr objectAtIndex:j] floatValue];
    telNoLbl.center=telNoLblPos;
    telNoLbl.bounds=telNoLblSize;


    CGPoint mobNoLblPos;
    CGRect mobNoLblSize;
mobNoLblPos.x=[[mXArr objectAtIndex:j] floatValue];
mobNoLblPos.y=[[mYArr objectAtIndex:j] floatValue];
mobNoLblSize.size.width=[[mWArr objectAtIndex:j] floatValue];
mobNoLblSize.size.height=[[mHArr objectAtIndex:j] floatValue];
    mobNoLbl.center=mobNoLblPos;
    mobNoLbl.bounds=mobNoLblSize;


    CGPoint emailLblPos;
    CGRect emailLblSize;
emailLblPos.x=[[emXArr objectAtIndex:j] floatValue];
emailLblPos.y=[[emYArr objectAtIndex:j] floatValue];
emailLblSize.size.width=[[emWArr objectAtIndex:j] floatValue];
emailLblSize.size.height=[[emHArr objectAtIndex:j] floatValue];
    emailLbl.center=emailLblPos;
    emailLbl.bounds=emailLblSize;


    CGPoint bCardFrontSubItem1Pos;
    CGRect bCardFrontSubItem1Rect;
bCardFrontSubItem1Pos.x=[[liXArr objectAtIndex:j] floatValue];
bCardFrontSubItem1Pos.y=[[liYArr objectAtIndex:j] floatValue];
bCardFrontSubItem1Rect.size.width=[[liWArr objectAtIndex:j] floatValue];
bCardFrontSubItem1Rect.size.height=[[liHArr objectAtIndex:j] floatValue];
    bCardFrontSubItem1.center=bCardFrontSubItem1Pos;
    bCardFrontSubItem1.bounds=bCardFrontSubItem1Rect;

bCardFront.image=[UIImage imageWithData:[bgImageArr objectAtIndex:j]];
bCardFrontSubItem1.image=[UIImage imageWithData:[logoImageArr objectAtIndex:j]];

} }

当我第一次单击按钮时,我的标签已对齐。但是当我继续点击同一个按钮时,屏幕上看不到“nameLbl”。我没有在这个项目的任何地方使用 hidden 或 alpha。谁能告诉我解决方案

4

1 回答 1

0

这应该适合你:

[nameLbl setFrame:CGRectMake([[dXArr objectAtIndex:0] floatValue], [[dYArr objectAtIndex:0] floatValue], [[dWArr objectAtIndex:0] floatValue], [[dHArr objectAtIndex:0] floatValue]];

您需要将数组中的值存储为 NSNumber。例如:

[dXArr addObject:[NSNumber numberWithFloat:1.0]];
于 2012-05-07T06:16:52.653 回答