0

ラベルの後に画像を追加するアプリケーションがありましたが、ラベルは動的です。その後、画像を追加する必要がありUILabelます。やってみた`

 dropdownlabel = [[UILabel alloc]init];
    [dropdownlabel setFrame:CGRectMake(90,8,180, 30)];
    [dropdownlabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];
    dropdownlabel.textAlignment = UITextAlignmentLeft;
    dropdownlabel.textColor = [UIColor whiteColor];
    dropdownlabel.numberOfLines = 0;
    dropdownlabel.text=@"gdhhgsfghdfagsfd ";

    dropdownlabel.backgroundColor =[UIColor clearColor];
   [navview addSubview:dropdownlabel];

    CGSize maximumLabelSize = CGSizeMake(9999,30);

    CGSize expectedLabelSize = [dropdownlabel.text sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]constrainedToSize:maximumLabelSize lineBreakMode:dropdownlabel.lineBreakMode]; 

    //adjust the label the the new height.
    CGRect newFrame = dropdownlabel.frame;
    newFrame.size.height = expectedLabelSize.height;
    dropdownlabel.frame = newFrame;


    NSLog(@"%f",newFrame.size.width);
    UIImageView *navview1=[[UIImageView alloc] initWithFrame:CGRectMake( newFrame.size.width+15,13,20,20)];
    navview1.image = [UIImage imageNamed:@"down_sml_arrow.png"];
    navview1.userInteractionEnabled=YES;
    [navview addSubview:navview1];

しかし、ある人にとっては正しいが、ある人にとっては間違っている。私が間違っている場所を教えてくれる人はいますか?

4

5 に答える 5

1
dropdownlabel = [[UILabel alloc]init];
[dropdownlabel setFrame:CGRectMake(90,8,180, 30)];
[dropdownlabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];
dropdownlabel.textAlignment = NSTextAlignmentRight;
dropdownlabel.textColor = [UIColor whiteColor];
dropdownlabel.numberOfLines = 0;
dropdownlabel.text=@"gdhhgsfghdfagsfd ";

dropdownlabel.backgroundColor =[UIColor clearColor];
[navview addSubview:dropdownlabel];

CGSize expectedLabelSize = [dropdownlabel.text sizeWithFont:dropdownlabel.font];

//adjust the label the the new height.
CGRect newFrame = dropdownlabel.frame;
newFrame.size = expectedLabelSize;
dropdownlabel.frame = newFrame;


UIImageView *navview1=[[UIImageView alloc] initWithFrame:CGRectMake(newFrame.origin.x+newFrame.size.width+15,13,20,20)];
navview1.image = [UIImage imageNamed:@"down_sml_arrow.png"];
navview1.userInteractionEnabled=YES;
[navview addSubview:navview1];
于 2013-06-21T06:59:53.410 に答える
1

ラベルの幅を動的に変更していると仮定しています。

 UIImageView *navview1=[[UIImageView alloc] initWithFrame:CGRectMake(dropdownlabel.frame.origin.x+dropdownlabel.frame.size.width+15 ,13,20,20)];

これがあなたを助けることを願っています。

于 2013-06-21T06:56:14.127 に答える