AnnBnnCnnD
AnnBnnCnnD
采纳率79.5%
2013-06-21 09:06 阅读 2.2k
已采纳

动态标签后添加图片

应用在标签后添加图片,标签是动态的。
实现代码:

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];
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    redCoral_ redCoral_ 2013-06-21 09:21
    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];
    
    点赞 评论 复制链接分享

相关推荐