How to set cornerRadius for only top-left and top-right corner of a UIView?

后端 未结 26 2962
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 06:14

Is there a way to set cornerRadius for only top-left and top-right corner of a UIView?

I tried the following, but it end up not seeing the

相关标签:
26条回答
  • 2020-11-22 07:15

    Emma: .TopRight and .BottomRight are not working for you perhaps because the call to view.roundCorners is done BEFORE final view bounds are calculated. Note that the Bezier Path derives from the view bounds at the time it is called. For example, if auto layout will narrow the view, the round corners on the right side might be outside the view. Try to call it in viewDidLayoutSubviews, where the view's bound is final.

    0 讨论(0)
  • 2020-11-22 07:15

    This is how you can set a corner radius for each corner of a button with Xamarin in C#:

    var maskPath = UIBezierPath.FromRoundedRect(MyButton.Bounds, UIRectCorner.BottomLeft | UIRectCorner.BottomRight,
        new CGSize(10.0, 10.0));
    var maskLayer = new CAShapeLayer
    {
        Frame = MyButton.Bounds,
        Path = maskPath.CGPath
    };
    MyButton.Layer.Mask = maskLayer;
    
    0 讨论(0)
提交回复
热议问题