
Hi, I want to implement a screen like in the image above. The data is coming from the server in the form of JSON string and I have parsed the data.
The code is as follows:
UILabel *lblTitle = [self createDynamicLabel:@"Seroquel"
contentFrame:CGRectMake(10, 5, 150, 20)
color:[UIColor blackColor]
font:[UIFont fontWithName:@"Arial-BoldMT" size:17]];
[scrollview addSubview:lblTitle];
[lblTitle release];
UILabel *lblGeneric = [self createDynamicLabel:@"Generic Name:"
contentFrame:CGRectMake(10, lblTitle.frame.size.height+5, 130, 20)
color:[UIColor blackColor]
font:[UIFont fontWithName:@"Arial-BoldMT" size:17]];
[scrollview addSubview:lblGeneric];
[lblGeneric release];
UILabel *lblGenericName = [self createDynamicLabel:DrugInfo.GenName
contentFrame:CGRectMake(lblGeneric.frame.size.width+5, 24, 150, 20)
color:[UIColor blackColor]
font:[UIFont fontWithName:@"Arial-BoldMT" size:17]];
[scrollview addSubview:lblGenericName];
[lblGenericName release];
UILabel *lblManufacturer = [self createDynamicLabel:@"Manufacturer:"
contentFrame:CGRectMake(10, 44, 115, 20)
color:[UIColor blackColor]
font:[UIFont fontWithName:@"Arial-BoldMT" size:17]];
[scrollview addSubview:lblManufacturer];
[lblManufacturer release];
UILabel *lblManufacturerName = [self createDynamicLabel:DrugInfo.Mtr
contentFrame:CGRectMake(115, 43, 150, 20)
color:[UIColor blackColor]
font:[UIFont fontWithName:@"Arial-BoldMT" size:17]];
[scrollview addSubview:lblManufacturerName];
[lblManufacturerName release];
//[self createDynamicView:CGRectMake(10, 70, 153, 128)];
UILabel *lblCommon = [self createDynamicLabel:@"Common uses:"
contentFrame:CGRectMake(10, 209, 110, 20)
color:[UIColor blackColor]
font:[UIFont fontWithName:@"Arial-BoldMT" size:17]];
lblCommon.backgroundColor = [UIColor whiteColor];
[lblCommon sizeToFit];
[scrollview addSubview:lblCommon];
[lblCommon release];
NSString *genericInfo = [NSString stringWithFormat:@" %@",DrugInfo.ComUse];
UILabel *lblCommonUse = [self createDynamicLabel:genericInfo
contentFrame:CGRectMake(10, 208, 310, 80)
color:[UIColor blackColor]
font:[UIFont fontWithName:@"Arial-BoldMT" size:17]];
//[lblCommonUse sizeToFit];
lblCommonUse.lineBreakMode = UILineBreakModeWordWrap;
lblCommonUse.numberOfLines = 0;
[scrollview addSubview:lblCommonUse];
[lblCommonUse release];
UILabel *lblBefore = [self createDynamicLabel:@" Before Using:"
contentFrame:CGRectMake(10, 294, 102, 20)
color:[UIColor blackColor]
font:[UIFont fontWithName:@"Arial-BoldMT" size:17]];
[lblBefore sizeToFit];
lblBefore.backgroundColor = [UIColor whiteColor];
[scrollview addSubview:lblBefore];
[lblBefore release];
genericInfo = [NSString stringWithFormat:@" %@",DrugInfo.BeforeUse];
UILabel *lblBeforeUse = [self createDynamicLabel:genericInfo
contentFrame:CGRectMake(10, 290, 308, 120)
color:[UIColor blackColor]
font:[UIFont fontWithName:@"Arial-BoldMT" size:17]];
lblBeforeUse.lineBreakMode = UILineBreakModeWordWrap;
lblBeforeUse.numberOfLines = 0;
[scrollview addSubview:lblBeforeUse];
[lblBeforeUse release];
}
}
}
-(UILabel *)createDynamicLabel:(NSString *)setTitle
contentFrame:(CGRect)labelFrame
color:(UIColor *)labelColor
font:(UIFont *)labelFont {
UILabel *dynamicLabel = [[UILabel alloc] init];
dynamicLabel.frame = labelFrame;
dynamicLabel.text = setTitle;
dynamicLabel.textColor = labelColor;
dynamicLabel.font = labelFont;
dynamicLabel.backgroundColor = [UIColor clearColor];
return dynamicLabel;
}
But if the data is more than can be displayed on the screen, it is clipping it and I want to display all the data. Can any one please help me do that?
Thanks in advance.
First Off, from what I can see you are adding your UI controls to a UIScrollView, if that is the case you need to make sure you are setting the contentSize property of the UIScrollView. The UIScrollView does not know how big the content is hold, so you need to figure this out and tell the UIScrollView.
This can be achieved quite easily if you set the frames for your controls using positioning variables (i.e CGFloat top; CGFloat left;) and update them as you add controls, instead of hardcoding the position values into your code. Something like this
Then at the end, you can use
topto make aCGSizeto set the contentSize.I also would suggest you look at using UITableView or using NSAttributedString as they might help you achieve what you want in other ways.