【发布时间】:2012-05-03 07:08:09
【问题描述】:
我有圆角矩形 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)
标签: ios cocoa-touch uibutton calayer