0

请帮我。我正在解决一个问题,在视图顶部显示一个删除按钮。

在此处输入图像描述

不使用像这样显示的贝塞尔路径

当我使用贝塞尔路径时显示如下

在此处输入图像描述

我如何显示按钮。

这是我正在使用的代码

UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
[view1 setBackgroundColor:[UIColor orangeColor]];

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view1.bounds byRoundingCorners:UIRectCornerTopLeft| UIRectCornerTopRight                                                         cornerRadii:CGSizeMake(10.0, 10.0)];
// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = view1.bounds;
maskLayer.path = maskPath.CGPath;
// Set the newly created shape layer as the mask for the image view's layer
view1.layer.mask = maskLayer;

[self.view addSubview:view1];

UIButton *bt1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[bt1 setTitle:@"D" forState:UIControlStateNormal];
[bt1 setFrame:CGRectMake(87, -10, 25, 25)];
[view1 addSubview:bt1];

请帮我。提前致谢。

4

1 回答 1

0

您始终可以根据视图的位置在您的超级视图中添加按钮。

@Larme 说的是真的,当你制作一个视图时,你会掩盖该视图的所有子视图。

如果您不想这样做,只需输入视图的 drawRect 并在那里绘制透明角以达到相同的效果。

于 2013-04-09T13:50:09.963 回答