2015-04-28 91 views
4

我有一個UIView,我想要刪除整個背景,所以它會採取紙的形狀。我試着將UI設置爲透明背景並使用代碼,但無論我做什麼,我總是以灰色半透明背景結束。這裏是我得到的當前輸出:enter image description here刪除UIVIew的背景 - 刪除矩形形狀

我該如何刪除灰色背景?我需要它作爲整個紙張顯示沒有殘留物。任何幫助?我試過如下:

//  self.view.backgroundColor = [UIColor clearColor]; 
// 
//  [self.view setOpaque:YES]; 
//  
    // self.view.backgroundColor = [UIColor clearColor];. 
    // self.view.layer.borderWidth = 0.0; 
    // self.view.layer.masksToBounds = YES; 
    // self.view.backgroundColor=[[UIColor clearColor] colorWithAlphaComponent:.0]; 

而且目前的UI配置爲:
enter image description here

如何管理刪除它!?任何幫助!?

編輯1 這是新的輸出 enter image description here

+0

我認爲你是什麼形象屏蔽之後:HTTP://計算器.com/questions/23488734/ios-sdk-image-masking – Zhang

+3

我認爲問題在於圖像本身具有灰色背景。您必須先使用圖像編輯程序將其刪除,然後將其作爲帶有Alpha通道的.png導入xcode。你可以給我發送那張圖片,如果你喜歡,我會爲你編輯它! –

+0

@張,我試圖遵循它,但我需要更多的細節,這是我第一次使用這種解決方法...你能幫忙嗎? –

回答

1

看起來像你的形象這是一個模式的看法裏面。如果是這樣的話請嘗試以下操作:

設置self.view.superview.backgroundColor[UIColor clearColor];viewWillLayoutSubviews

例內

- (void)viewWillLayoutSubviews 
{ 

    [super viewWillLayoutSubviews]; 
    self.view.superview.layer.masksToBounds = YES; 
    self.view.superview.backgroundColor = [UIColor clearColor]; 
} 
+0

首先是它是在一個模態視圖,一個彈出窗口,第二次BackGround確實改變了第一次!仍然不是理想的結果,但我想它真的很接近!你能檢查編輯1看到新的輸出!?我能做什麼 !? –

+1

它的工作!如果只有我改變self.view。superview.layer.masksToBounds = YES;並把它放到self.view.superview.layer.masksToBounds = NO;它會得到所需的效果..非常感謝! –