0
我有圓角的矩形UIButton,並希望爲它添加陰影,但是當我設置背景圖像陰影不可見時,我認爲背景覆蓋了陰影。沒有背景圖像陰影是可見自定義UIButton的影子
customBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
customBtn.frame=CGRectMake(customBtn.frame.origin.x, customBtn.frame.origin.y, 30, 30);
[customBtn setImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
[customBtn setBackgroundImage:[[UIImage imageNamed:@"bg.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:0] forState:UIControlStateNormal];
customBtn.layer.cornerRadius=9;
customBtn.layer.shadowColor = [UIColor redColor].CGColor;
customBtn.layer.shadowOpacity = 1.0;
customBtn.layer.shadowRadius = 1;
customBtn.layer.shadowOffset = CGSizeMake(2.0f, 2.0f);
customBtn.clipsToBounds=YES;
嘗試刪除clipToBounds = YES(或將其設置爲NO) – giorashc