程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-動態標簽後添加圖片

ios-動態標簽後添加圖片

編輯:編程綜合問答
動態標簽後添加圖片

應用在標簽後添加圖片,標簽是動態的。
實現代碼:

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];

最佳回答:


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];
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved