2015-04-03 48 views
0

引用this answer,我試圖讓UIImageView顯示一個圓形圖像。我生成了一個面具,並嘗試使用該圖像來掩蓋它,但那也不起作用。SetMasksToBounds時圖像消失:YES

當我試圖掩蓋圖像或更改角落時,什麼也沒有發生。 這就是: [proPic.layer setCornerRadius:proPic.frame.size.width/2];

當我打電話給[proPic.layer setMasksToBounds:YES];圖像完全消失。當我嘗試使用third party library來掩蓋圖像時,也是如此。

有什麼建議嗎?

編輯:

//Profile Picture 
proPic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"DummyProPic"]]; 
//Mask Profile Picture to be circular 
[proPic.layer setCornerRadius:proPic.frame.size.width/2]; 
//With this line added, the picture disappears 
//Without this line, nothing is done to mask the image 
[proPic.layer setMasksToBounds:YES]; 

[self.contentView addSubview:proPic]; 
[proPic mas_makeConstraints:^(MASConstraintMaker *make) { 

    make.top.equalTo(self.contentView.mas_top).with.offset(padding.top); 
    make.centerX.equalTo(self.contentView.mas_centerX); 
    make.height.equalTo(@120); 
    make.width.equalTo(@120); 
}]; 
+0

你可以發佈你的代碼嗎? – NobodyNada 2015-04-03 01:18:56

+0

你的代碼看起來不錯,你確定'proPic'是用'IBOutlet'聲明的,在左邊(在行號旁邊),有一個實心圓圈,表示有一個連接到你的故事板(假設這就是你使用的)? – paulvs 2015-04-03 02:25:49

+0

我不使用故事板。我會看看我是否有更多相關的代碼。 – jboulter11 2015-04-03 02:35:15

回答

0

您應該刪除.layer用於屏蔽到邊界。嘗試:

[proPic setMasksToBounds:YES]; 
+0

不是UIImageView的一種方法 – jboulter11 2015-04-03 03:16:28

0
[proPic.layer setCornerRadius:60]; 
[proPic.layer setMasksToBounds:YES]; 

這個工作,它不喜歡的proPic.frame.size.width/2部分。

0

如果setMasksToBounds創建問題,然後除去遮蔽,你可以用以下

proPic.clipsToBounds=YES;

它可以幫助你試試。