2013-01-17 19 views
1

我想创造我的iPhone和iPad应用程序的布局自动重排基于动态数据。 更具体些,这意味着我有几个对象。每个对象都有一个特定的类型和相关的数据。 数据是应该显示什么,类型决定了它应该如何显示。一种类型可能是文本,这意味着它应该显示为简单的文本而没有交互的可能性。另一种类型可能是日期,这意味着它应该显示为一个控件,用户可以在点击时选择一个日期。自动流动的布局,嵌入式控制和自动文本断

现在,问题是,我想要显示的对象是在数量和相关联的数据的动态,所以无法在静态位置定位控制。

This jsfiddle显示我的意思是什么样的布局。根据div的宽度,内容会自动重新流动,日期输入控件将显示在文本的中间。

我找不到任何支持这种场景的控件 - 那么我该如何去实现这个?

+0

听起来像是HTML工作? – eggyal

+0

@eggyal:我想使用原生小部件来完成它。 –

回答

2

Here是使用CoreText解决部分类似问题的示例。也许这会让你指向这个方向。

- (CFArrayRef)copyRectangularPathsForPath:(CGPathRef)path 
            height:(CGFloat)height { 
    CFMutableArrayRef paths = CFArrayCreateMutable(NULL, 0, 
                &kCFTypeArrayCallBacks); 

    // First, check if we're a rectangle. If so, we can skip the hard parts. 
    CGRect rect; 
    if (CGPathIsRect(path, &rect)) { 
     CFArrayAppendValue(paths, path); 
    } 
    else { 
     // Build up the boxes one line at a time. If two boxes have the 
     // same width and offset, then merge them. 
     CGRect boundingBox = CGPathGetPathBoundingBox(path); 
     CGRect frameRect = CGRectZero; 
     for (CGFloat y = CGRectGetMaxY(boundingBox) - height; 
        y > height; y -= height) { 
      CGRect lineRect = 
        CGRectMake(CGRectGetMinX(boundingBox), y, 
           CGRectGetWidth(boundingBox), height); 
      CGContextAddRect(UIGraphicsGetCurrentContext(), lineRect); 

      // Do the math with full precision so we don't drift, 
      // but do final render on pixel boundaries. 
      lineRect = CGRectIntegral(clipRectToPath(lineRect, path)); 
      CGContextAddRect(UIGraphicsGetCurrentContext(), lineRect); 

      if (! CGRectIsEmpty(lineRect)) { 
       if (CGRectIsEmpty(frameRect)) { 
        frameRect = lineRect; 
       } 
       else if (frameRect.origin.x == lineRect.origin.x && 
         frameRect.size.width == lineRect.size.width) { 
        frameRect = CGRectMake(lineRect.origin.x,                                  lineRect.origin.y,                                  lineRect.size.width, 
           CGRectGetMaxY(frameRect) - CGRectGetMinY(lineRect)); 
       } 
       else { 
        CGMutablePathRef framePath = 
             CGPathCreateMutable(); 
        CGPathAddRect(framePath, NULL, frameRect); 
        CFArrayAppendValue(paths, framePath); 

        CFRelease(framePath); 
        frameRect = lineRect; 
       } 
      } 
     } 

     if (! CGRectIsEmpty(frameRect)) { 
      CGMutablePathRef framePath = CGPathCreateMutable(); 
      CGPathAddRect(framePath, NULL, frameRect); 
      CFArrayAppendValue(paths, framePath); 
      CFRelease(framePath); 
     }   
    } 

    return paths; 
}