我需要制作UILabel(4)的动态高度和y原点。我知道第一个标签的y原点。但是高度,它的行数应该根据其中动态变化的内容而变化。所以根据第一个标签,第二个标签的 y-origin 应该开始并且与第一个相同,它应该根据内容自动调整其高度和行数。对于第三个和第四个标签也是如此
这是我需要得到的格式:
Name: Wilston Works
Working Days: Sun,Mon,Tue,Wed,Thu, // Here only upto Thur then Workinh hrs should start after that
Fri
Working hrs:9 to 5
Specialities:General,parties,festival
specials,..............
....... //lines depends on content may be 1 to many
我的代码:
displayName =[[UILabel alloc] init];
[displayName setFrame:CGRectMake(10, companyaccess.frame.size.height+companyaccess.frame.origin.y,300, 30)]; //companyaccess is the label above this label
displayName.textAlignment = UITextAlignmentLeft;
displayName.backgroundColor = [UIColor clearColor];
self.displayName.text= [NSString stringWithFormat:@" Name :"];
[displayName setFont:[UIFont fontWithName:@"Helvetica" size:14]];
[self.view addSubview:displayCompanyName];
NSString *displayname1=[NSString stringWithFormat:@"%@",id1];
CGSize constraint6 = CGSizeMake(250, 2000.0f);
CGSize size6=[displaycompanyname1 sizeWithFont:[UIFont fontWithName:@"Helvetica-Bold" size:14] constrainedToSize:constraint6 lineBreakMode:UILineBreakModeWordWrap];
displayName1 =[[UILabel alloc] init];
[displayName1 setFrame:CGRectMake(155,companyaccess.frame.size.height+companyaccess.frame.origin.y,self.view.bounds.size.width,30) ];
displayName1.textAlignment=UITextAlignmentLeft;
displayName1.backgroundColor=[UIColor clearColor];
[displayName1 setNumberOfLines:0];
[displayName1 sizeToFit];
displayName1.text=[NSString stringWithFormat:@"%@ " ,displayname1];
displayName1.highlightedTextColor=[UIColor blackColor];
[displayName1 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
[self.view displayName1];
displayWorkingDays=[[UILabel alloc] init];
[displayWorkingDays setFrame:CGRectMake(10,displayName1.frame.size.height+displayName1.frame.origin.y,self.view.bounds.size.width,30)];
displayWorkingDays.textAlignment=UITextAlignmentLeft;
displayWorkingDays.backgroundColor=[UIColor clearColor];
displayWorkingDays.text=[NSString stringWithFormat:@"Working Days :"];
[self.view addSubview:displayWorkingDays];
displayWorkingDays1=[[UILabel alloc] init];
[displayWorkingDays1 setFrame:CGRectMake(150,displayName1.frame.size.height+displayName1.frame.origin.y,self.view.bounds.size.width,40)];
displayWorkingDays1.numberOfLines=0;
displayWorkingDays1.textAlignment=UITextAlignmentLeft;
displayWorkingDays1.backgroundColor=[UIColor clearColor];
displayWorkingDays1.text=[NSString stringWithFormat:@"%@",temp1];
displayWorkingDays1.font=[UIFont fontWithName:@"arial" size:14];
[displayWorkingDays1 sizeToFit];
[self.view addSubview:displayWorkingDays1];
............// for all the labels.But I could not get what i desired.
}
请为我提供一个满足上述标准的 gud 示例。bcoz 我尝试过的所有示例都在某些情况下工作,而在其他情况下无法工作。
任何帮助将不胜感激。