Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 5th, 2012  |  syntax: None  |  size: 1.56 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. xCode dynamically add fields
  2. Array:(
  3.         {
  4.         fieldName = Full Name;
  5.         value = Neil G.;
  6.     },
  7.         {
  8.         fieldName = Aboutn me;
  9.         value = "a web dev..";
  10.     },
  11.         {
  12.         fieldName = State;
  13.         value = Colorado;
  14.     },
  15.         {
  16.         fieldName = City;
  17.         value = Denver;
  18.     },
  19.         {
  20.         fieldName = Website;
  21.         value = "http://google.com";
  22.     },
  23.         {
  24.         fieldName = College University;
  25.         value = "DSU";
  26.     },
  27.         {
  28.         fieldName = Graduation Year;
  29.         value = 2011;
  30.     }
  31. )
  32.        
  33. UIView *wrapperView = [[UIView alloc] initWithFrame:self.view.frame];
  34. [self.view addSubView:wrapperView];
  35. UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:wrapperView.frame];
  36. [wrapperView addSubView:scrollView];
  37.        
  38. double heightNeeded = 0;
  39. for(int i = 0; i < fieldCount; i++){
  40.    heightNeeded = heightNeeded + 31;
  41. }
  42. if(heightNeeded < scrollView.frame.size.height){
  43.     heightNeeded = scrollView.frame.size.height;
  44. }
  45.        
  46. [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width,heightNeeded)];
  47. int currentY = 0;
  48. for(Details *thisDetail in Array){
  49.    UILabel *thisLabel = [[UILabel alloc]  initWithFrame:CGRectMake(0,currentY,scrollView.frame.size.width,21)];
  50.     [thisLabel setLineBreakMode:UILineBreakModeWordWrap];
  51.     thisLabel.numberOfLines = 0;
  52.     UILabel.text = [NSString stringWithFormat:@"%@: %@",thisDetail.fieldName,thisDetail.Value];
  53.     [thisLabel sizeToFit];
  54.     [scrollView addSubView thisLabel];
  55.     currentY = currentY + thisLabel.frame.origin.y + thisLabel.frame.size.height + 10;
  56.  }