2012-01-29 102 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]; 
}