Ios 如何在uiview的底部像键盘上的旧空格键一样画一条弧?

Ios 如何在uiview的底部像键盘上的旧空格键一样画一条弧?,ios,objective-c,Ios,Objective C,我有一个UIView我只需要在UIView的左下角和右下角画一个弧,就像一个弧,比如键盘上的旧空格键?你说的“比如键盘上的旧空格键”有点不清楚,但听起来你需要做一个自定义的UIView 您可以通过以下方式实现: 创建UIView的子类并重写-(void)drawRect:(CGRect)rect 在这里,您可以使用UIBezierPath BezerPath可以表示大量的形状和形式 根据您想要绘制的内容,它将类似于: -(void)drawRect:(CGRect)rect { [sup

我有一个UIView我只需要在UIView的左下角和右下角画一个弧,就像一个弧,比如键盘上的旧空格键?

你说的“比如键盘上的旧空格键”有点不清楚,但听起来你需要做一个自定义的UIView

您可以通过以下方式实现:

创建
UIView
的子类并重写
-(void)drawRect:(CGRect)rect

在这里,您可以使用
UIBezierPath

BezerPath可以表示大量的形状和形式

根据您想要绘制的内容,它将类似于:

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

     for (UIBezierPath * path in self.paths) {
        CGContextAddPath(ctx, path.CGPath);
        CGContextSetStrokeColorWithColor(ctx,self.color.CGColor);
        CGContextStrokePath(ctx);
     }

如果要执行此操作,请参见此:

您可以使用以下代码:

NSInteger marginCurve = 30;

    UIView *example1 = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 2)];
    [example1 setBackgroundColor: [UIColor clearColor]];

    UIBezierPath *curve1 = [UIBezierPath bezierPath];
    [curve1 moveToPoint: CGPointMake(0, 0)];
    [curve1 addLineToPoint: CGPointMake(example1.frame.size.width, 0)];
    [curve1 addLineToPoint: CGPointMake(example1.frame.size.width, example1.frame.size.height - marginCurve)];
    [curve1 addCurveToPoint: CGPointMake(0, example1.frame.size.height - marginCurve)
              controlPoint1: CGPointMake(example1.frame.size.width / 2, example1.frame.size.height)
              controlPoint2: CGPointMake(example1.frame.size.width / 2, example1.frame.size.height)];
    [curve1 closePath];

    CAShapeLayer *ex1Layer = [CAShapeLayer layer];
    [ex1Layer setFrame: example1.bounds];
    [ex1Layer setFillColor: [UIColor brownColor].CGColor];
    [ex1Layer setPath: curve1.CGPath];

    [example1.layer addSublayer: ex1Layer];
    [self.view addSubview: example1];

我希望它能帮助你:)

使边缘圆润我想要它像微笑一样的曲线curve@roshan.k你为什么要说空格键?老式的空格键不是弯曲的,想象一个微笑…一个弯曲的微笑,它非常接近我所需要的