2013-03-13 37 views
4

我有一個UIView其中包含其他子視圖。我將邊框應用於此UIView,並將邊框應用於整個UIView。爲了那看見第一個圖象。如何從UIView的某個部分刪除邊框?

enter image description here

但不想讓身邊的標題在那裏說:"Leaderboard"邊界。我如何才能刪除該部分的邊界只。見下面的圖片,並在看到周圍有頭排行榜沒有邊界..

enter image description here

+0

你需要自定義你的視圖。像一個視圖將包含標題「領導者視圖」和其他視圖將包含原始內容.. – Ganapathy 2013-03-13 06:31:08

+0

您可以自定義視圖或繪製自定義視圖 – 2013-03-13 06:36:19

回答

2

NO,CALayer邊界不支持這種行爲。

但是,如果您需要實現此功能,您可以嘗試其他方法, 嘗試在主視圖的每一側添加一個帶所需邊框顏色作爲其背景色的n點寬不透明子視圖。

添加以下代碼:

CGSize mainViewSize = theView.bounds.size; 
CGFloat borderWidth = 2; 
UIColor *borderColor = [UIColor redColor]; 
CGFloat heightfromTop = 25; 
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, heightfromTop borderWidth, mainViewSize.height-heightfromTop)]; 
UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(mainViewSize.width - borderWidth, heightfromTop, borderWidth, mainViewSize.height-heightfromTop)]; 
leftView.opaque = YES; 
rightView.opaque = YES; 
leftView.backgroundColor = borderColor; 
rightView.backgroundColor = borderColor; 

[mainView addSubview:leftView]; 
[mainView addSubview:rightView]; 

這將添加邊框兩側only.Repeat頂部和底部也同樣的想法。

NBheightfromTop是頂部,你不希望邊框看法是存在的高度,你可以改變它,按您的需求

+0

但是可以自定義視圖或繪製自定義視圖 – 2013-03-13 06:35:44

+0

@MidhunMP是的,當然。看到我編輯的答案,有一種很棒的方式 – 2013-03-13 06:39:41

+0

@MicRO ..但我不會在視圖的底角獲得圓角 – Shaunak 2013-03-13 06:41:39

1

你也可以繼承的UIView貫徹drawRect像:

- (void)drawRect:(CGRect)rect 
{  
     float borderSize = 3.0f; 

    //draw the bottom border 
    CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor); 
    CGContextFillRect(context, CGRectMake(0.0f, self.frame.size.height - borderSize, self.frame.size.width, borderSize)); 

    //draw the right border 
    CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor); 
    CGContextFillRect(context, CGRectMake(0.0f,0.0f, borderSize,self.frame.size.height)); 

    //draw the left border 
    CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor); 
    CGContextFillRect(context, CGRectMake(self.frame.size.width - borderSize,0.0f, borderSize,self.frame.size.height)); 
} 

現在,你需要使用的子類UIView創建所需的視圖。