-1

我有多个图像。当用户选择特定图像时,我必须使用顶部带有箭头的视图突出显示该图像。只需使用顶部有尖锐箭头边缘的图像即可解决此问题,但我想使用 uiview 来实现。如何UIView在 iPhone 中使用核心图形的顶部中间创建一个尖锐的箭头边缘。就像 iPad 中的 popover 尖箭头边缘。

谁能帮我。提前致谢。

4

4 回答 4

10

是的,你可以通过使用 UIView 来做到这一点。使用UIBezierPath根据需要创建路径

然后将路径添加到图形上下文并填充您想要的颜色。

示例代码如下所示:

#define kArrowHeight 50   

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    UIBezierPath *fillPath = [UIBezierPath bezierPath];
    [fillPath moveToPoint:CGPointMake(0, self.bounds.origin.y+kArrowHeight)];
    [fillPath addLineToPoint:CGPointMake(self.bounds.size.width/2-(kArrowHeight/2), kArrowHeight)];
    [fillPath addLineToPoint:CGPointMake(self.bounds.size.width/2, 0)];
    [fillPath addLineToPoint:CGPointMake(self.bounds.size.width/2+(kArrowHeight/2), kArrowHeight)];
    [fillPath addLineToPoint:CGPointMake(self.bounds.size.width, kArrowHeight)];
    [fillPath addLineToPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height)];
    [fillPath addLineToPoint:CGPointMake(0, self.bounds.size.height)];
    [fillPath closePath];

    CGContextAddPath(context, fillPath.CGPath);
    CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor);
    CGContextFillPath(context);

}

上面的代码将为您提供一个视图,其中包含 UIView 中间的锐边,看起来像弹出框,如下所示。

在此处输入图像描述

请注意:

  • 您可以根据需要更改路径。
  • 视图的背景颜色应该是清晰的颜色。
于 2013-06-04T08:30:25.210 回答
2

试试这个真的很有趣 https://github.com/werner77/WEPopover , https://github.com/runway20/PopoverView

于 2013-06-04T05:59:29.190 回答
0

如果其适用于 iPad 的应用程序,您可以使用 uipopovercontroller。Else for iphone 你可以在 github 上找到各种控件

于 2013-06-04T05:50:11.817 回答
0

您可以使用 UIView 作为容器,并将 UIView 背景设置为透明。接下来,在容器中添加一个子 UIView,并在顶部边缘添加一个箭头(UIImageView)。

于 2013-06-04T05:53:25.530 回答