2 annbnncnnd AnnBnnCnnD 于 2013.06.21 17:06 提问

动态标签后添加图片

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

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 17: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];
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!