2012-01-29 90 views

回答

4

你有3种基本方法:

  1. 使用QuartzCore并重写的drawRect:在自定义UIView子类
  2. 集,其中包含每个图像
  3. 创建的UIViews的UIImageView的层属性的边框宽度和边框颜色水平线的高度为1,垂直线的宽度为1,设置视图的背景颜色并将它们添加为子视图

3可能是e尽可能实现,但不是最优雅的,1是内存方面最强大的,因为您也可以使用drawInRect将您的图像绘制到相同的图形上下文中。这将视图层次结构折叠为单个视图。

3

您可以使用图层它做的是回答以上或只是因为你只想线,使用UIViews

就这样

for(i=0;i<numberOfLine*heightofImage;i+=heightOfImage) { 
    UIView *horizontalLine=[[UIView alloc]initWithFrame:CGRectMake(x, i, height, 1)]; 
    [self.view addSubView:horizontalLine]; 
} 

希望帮助

+0

这是上述答案的第三个选项。尽管可以添加代码。 – 2012-01-29 10:58:41

+0

yahh !!无论如何..重点是帮助:) – 2012-01-29 11:48:05

0

我以前张贴的第三个选项由Magic Bullet Dave开发,它工作的很棒。这里的代码:

UIView *borderBottom = [[UIView alloc] initWithFrame:CGRectMake(0.0, 10, widthDesired, 1.0)]; 
borderBottom.backgroundColor = [UIColor grayColor]; 
[myView addSubview:borderBottom]; 

如果你想做一个垂直线,你只需使用宽度1,然后所需的高度。

1
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    UIView *verticalLine = [[UIView alloc] initWithFrame:CGRectMake(roundf(self.view.bounds.size.width/2), 0.0, 1.0, self.view.bounds.size.height)]; 
    verticalLine.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5]; 
    verticalLine.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin; 
    [self.view addSubview:verticalLine]; 

    UIView *horizontalLine = [[UIView alloc] initWithFrame:CGRectMake(0.0, roundf(self.view.bounds.size.height/2), self.view.bounds.size.width, 1.0)]; 
    horizontalLine.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5]; 
    horizontalLine.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 
    [self.view addSubview:horizontalLine]; 
} 
相关问题