kur*_*kun 15 iphone z-order calayer
我搜索过但找不到这种行为的原因.
我有一个我正在设置的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];
Run Code Online (Sandbox Code Playgroud)
我不明白为什么边框出现在deleteMark子视图上方.有没有办法达到预期的效果?
谢谢!
MrM*_*age 16
来自Apple的文档CALayer:
边框是通过borderWidth从接收器的边界插入的.它在接收器的内容和子层上方合成,并包含cornerRadius属性的效果.
为了获得您想要的效果,我建议您将图像放入自己的子视图/子图层并设置该子图层的borderWidth属性.
| 归档时间: |
|
| 查看次数: |
4261 次 |
| 最近记录: |