我已经搜索过但找不到这种行为的原因。
我有一个设置图像的UIButton。下面是按钮应该出现的样子。请注意,这只是所需按钮设计的Photoshop:
本质上,它是一个带有白色边框和一些周围阴影的正方形自定义UIButton。在右上角,将作为子视图以编程方式添加“X”标记。
以下是实际应用程序中按钮的屏幕截图。此时,我仅添加了一个阴影和一个作为子视图的X标记:
然而,当我尝试添加白色边框时,它看起来像这样:
似乎白色边框出现在X标记子层之上。我不知道为什么。
以下是我正在使用的代码:
// selectedPhotoButton is the UIButton with UIImage set earlier
// At this point, I am adding in the shadow
[selectedPhotoButton layer] setShadowColor:[[UIColor lightGrayColor] CGColor]];
[[selectedPhotoButton layer] setShadowOffset: CGSizeMake(1.0f, 1.0f)];
[[selectedPhotoButton layer] setShadowRadius:0.5f];
[[selectedPhotoButton layer] setShadowOpacity:1.0f];
// Now add the white border
[[selectedPhotoButton layer] setBorderColor:[[UIColor whiteColor] CGColor]];
[[selectedPhotoButton layer] setBorderWidth:2.0];
// Now add the X mark subview
UIImage *deleteImage = [UIImage imageNamed:@"nocheck_photo.png"];
UIImageView *deleteMark = [[UIImageView alloc] initWithFrame:CGRectMake(53, -5, 27, 27)];
deleteMark.contentMode = UIViewContentModeScaleAspectFit;
[deleteMark setImage:deleteImage];
[selectedPhotoButton addSubview:deleteMark];
[deleteMark release];
我不明白为什么边框出现在deleteMark子视图的上方。有没有办法获得预期的效果?
谢谢!