Rounded Curve Edge for UIViewUIBezierPath Triangle with rounded edgesAnimate CAShapeLayer path on animated bounds changeUIView with curved edges (not corner radius)Use Storyboard to mask UIView and give rounded corners?How to automatically update the child view when the parent view's frame changes?Wrong position of CAShapelayer in sublayers of UIViewHow to cut edges of a uiview in swiftHow to correctly handle this on iPhone XStrange animation occurs when extending UIViewCreate a UIView with rounded bottom edge

Why isn't there armor to protect from spells in the Potterverse?

Windows 10 deletes lots of tiny files super slowly. Anything that can be done to speed it up?

How can I tell the difference between fishing for rolls and being involved?

How to stop the death waves in my city?

What are examples of EU policies that are beneficial for one EU country, disadvantagious for another?

Beyond Futuristic Technology for an Alien Warship?

How can this Stack Exchange site have an animated favicon?

Adding a symbol to the top of a vertex in a connected tree

Clear text passwords in Unix

What happens to a net with the Returning Weapon artificer infusion after it hits?

Whaling ship logistics

Is there a concept of "peer review" in Rabbinical Judaism?

Difference between "rip up" and "rip down"

A famous scholar sent me an unpublished draft of hers. Then she died. I think her work should be published. What should I do?

Suffocation while cooking under an umbrella?

New road bike: alloy dual pivot brakes work poorly

Diminutive -ula

Why does my browser attempt to download pages from http://clhs.lisp.se instead of viewing them normally?

Are fuzzy sets appreciated by OR community?

We are on WHV, my boyfriend was in a small collision, we are leaving in 2 weeks what happens if we don’t pay the damages?

I reverse the source code, you reverse the input!

Why weren't the Death Star plans transmitted electronically?

Flowers sent by the birds

I am not a pleasant sight



Rounded Curve Edge for UIView


UIBezierPath Triangle with rounded edgesAnimate CAShapeLayer path on animated bounds changeUIView with curved edges (not corner radius)Use Storyboard to mask UIView and give rounded corners?How to automatically update the child view when the parent view's frame changes?Wrong position of CAShapelayer in sublayers of UIViewHow to cut edges of a uiview in swiftHow to correctly handle this on iPhone XStrange animation occurs when extending UIViewCreate a UIView with rounded bottom edge






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am trying to add rounded edges via this extension , however I am getting proper rounded UIView in iPhone X but when I try to run this same code in iPhone 6s , its like not getting curved , tried to increase the desiredCurve still not able to see the curve.



extension UIView 


/* Usage Example
* bgView.addBottomRoundedEdge(desiredCurve: 1.5)
*/
func addBottomRoundedEdge(desiredCurve: CGFloat?)
let offset: CGFloat = self.frame.width / desiredCurve!
let bounds: CGRect = self.bounds

let rectBounds: CGRect = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.size.width, height: bounds.size.height / 2)
let rectPath: UIBezierPath = UIBezierPath(rect: rectBounds)
let ovalBounds: CGRect = CGRect(x: bounds.origin.x - offset / 2, y: bounds.origin.y, width: bounds.size.width + offset, height: bounds.size.height)
let ovalPath: UIBezierPath = UIBezierPath(ovalIn: ovalBounds)
rectPath.append(ovalPath)

// Create the shape layer and set its path
let maskLayer: CAShapeLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.path = rectPath.cgPath

// Set the newly created shape layer as the mask for the view's layer
self.layer.mask = maskLayer




enter image description here










share|improve this question


























  • why don't you use roundedRect rather than rect and oval. Doesn't seem to be doing what you intend

    – Steve O'Connor
    Sep 25 '18 at 13:08











  • try putting it in viewDidLayoutSubviews or layoutSubviews if using UIViewController and UIView sub-classes respectively.

    – ChanOnly123
    Sep 25 '18 at 13:09











  • I can't imagine you will use this styling cue in more than one or two view controllers and to extend UIView, the building block of UIKit, the ultimate superclass, for this is IMO not a decision that I would make. This would be much better handled by using an asset, like a PNG. If you're doing an animation that adjusts the radius, like a pull-to-refresh, I still wouldn't extend UIView for that, I'd keep it as local as possible.

    – bsod
    Mar 28 at 18:45


















0















I am trying to add rounded edges via this extension , however I am getting proper rounded UIView in iPhone X but when I try to run this same code in iPhone 6s , its like not getting curved , tried to increase the desiredCurve still not able to see the curve.



extension UIView 


/* Usage Example
* bgView.addBottomRoundedEdge(desiredCurve: 1.5)
*/
func addBottomRoundedEdge(desiredCurve: CGFloat?)
let offset: CGFloat = self.frame.width / desiredCurve!
let bounds: CGRect = self.bounds

let rectBounds: CGRect = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.size.width, height: bounds.size.height / 2)
let rectPath: UIBezierPath = UIBezierPath(rect: rectBounds)
let ovalBounds: CGRect = CGRect(x: bounds.origin.x - offset / 2, y: bounds.origin.y, width: bounds.size.width + offset, height: bounds.size.height)
let ovalPath: UIBezierPath = UIBezierPath(ovalIn: ovalBounds)
rectPath.append(ovalPath)

// Create the shape layer and set its path
let maskLayer: CAShapeLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.path = rectPath.cgPath

// Set the newly created shape layer as the mask for the view's layer
self.layer.mask = maskLayer




enter image description here










share|improve this question


























  • why don't you use roundedRect rather than rect and oval. Doesn't seem to be doing what you intend

    – Steve O'Connor
    Sep 25 '18 at 13:08











  • try putting it in viewDidLayoutSubviews or layoutSubviews if using UIViewController and UIView sub-classes respectively.

    – ChanOnly123
    Sep 25 '18 at 13:09











  • I can't imagine you will use this styling cue in more than one or two view controllers and to extend UIView, the building block of UIKit, the ultimate superclass, for this is IMO not a decision that I would make. This would be much better handled by using an asset, like a PNG. If you're doing an animation that adjusts the radius, like a pull-to-refresh, I still wouldn't extend UIView for that, I'd keep it as local as possible.

    – bsod
    Mar 28 at 18:45














0












0








0








I am trying to add rounded edges via this extension , however I am getting proper rounded UIView in iPhone X but when I try to run this same code in iPhone 6s , its like not getting curved , tried to increase the desiredCurve still not able to see the curve.



extension UIView 


/* Usage Example
* bgView.addBottomRoundedEdge(desiredCurve: 1.5)
*/
func addBottomRoundedEdge(desiredCurve: CGFloat?)
let offset: CGFloat = self.frame.width / desiredCurve!
let bounds: CGRect = self.bounds

let rectBounds: CGRect = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.size.width, height: bounds.size.height / 2)
let rectPath: UIBezierPath = UIBezierPath(rect: rectBounds)
let ovalBounds: CGRect = CGRect(x: bounds.origin.x - offset / 2, y: bounds.origin.y, width: bounds.size.width + offset, height: bounds.size.height)
let ovalPath: UIBezierPath = UIBezierPath(ovalIn: ovalBounds)
rectPath.append(ovalPath)

// Create the shape layer and set its path
let maskLayer: CAShapeLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.path = rectPath.cgPath

// Set the newly created shape layer as the mask for the view's layer
self.layer.mask = maskLayer




enter image description here










share|improve this question
















I am trying to add rounded edges via this extension , however I am getting proper rounded UIView in iPhone X but when I try to run this same code in iPhone 6s , its like not getting curved , tried to increase the desiredCurve still not able to see the curve.



extension UIView 


/* Usage Example
* bgView.addBottomRoundedEdge(desiredCurve: 1.5)
*/
func addBottomRoundedEdge(desiredCurve: CGFloat?)
let offset: CGFloat = self.frame.width / desiredCurve!
let bounds: CGRect = self.bounds

let rectBounds: CGRect = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.size.width, height: bounds.size.height / 2)
let rectPath: UIBezierPath = UIBezierPath(rect: rectBounds)
let ovalBounds: CGRect = CGRect(x: bounds.origin.x - offset / 2, y: bounds.origin.y, width: bounds.size.width + offset, height: bounds.size.height)
let ovalPath: UIBezierPath = UIBezierPath(ovalIn: ovalBounds)
rectPath.append(ovalPath)

// Create the shape layer and set its path
let maskLayer: CAShapeLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.path = rectPath.cgPath

// Set the newly created shape layer as the mask for the view's layer
self.layer.mask = maskLayer




enter image description here







swift xcode cashapelayer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 25 '18 at 12:47









Amit

2,6823 gold badges17 silver badges34 bronze badges




2,6823 gold badges17 silver badges34 bronze badges










asked Sep 25 '18 at 10:18









rishabh shuklarishabh shukla

12 bronze badges




12 bronze badges















  • why don't you use roundedRect rather than rect and oval. Doesn't seem to be doing what you intend

    – Steve O'Connor
    Sep 25 '18 at 13:08











  • try putting it in viewDidLayoutSubviews or layoutSubviews if using UIViewController and UIView sub-classes respectively.

    – ChanOnly123
    Sep 25 '18 at 13:09











  • I can't imagine you will use this styling cue in more than one or two view controllers and to extend UIView, the building block of UIKit, the ultimate superclass, for this is IMO not a decision that I would make. This would be much better handled by using an asset, like a PNG. If you're doing an animation that adjusts the radius, like a pull-to-refresh, I still wouldn't extend UIView for that, I'd keep it as local as possible.

    – bsod
    Mar 28 at 18:45


















  • why don't you use roundedRect rather than rect and oval. Doesn't seem to be doing what you intend

    – Steve O'Connor
    Sep 25 '18 at 13:08











  • try putting it in viewDidLayoutSubviews or layoutSubviews if using UIViewController and UIView sub-classes respectively.

    – ChanOnly123
    Sep 25 '18 at 13:09











  • I can't imagine you will use this styling cue in more than one or two view controllers and to extend UIView, the building block of UIKit, the ultimate superclass, for this is IMO not a decision that I would make. This would be much better handled by using an asset, like a PNG. If you're doing an animation that adjusts the radius, like a pull-to-refresh, I still wouldn't extend UIView for that, I'd keep it as local as possible.

    – bsod
    Mar 28 at 18:45

















why don't you use roundedRect rather than rect and oval. Doesn't seem to be doing what you intend

– Steve O'Connor
Sep 25 '18 at 13:08





why don't you use roundedRect rather than rect and oval. Doesn't seem to be doing what you intend

– Steve O'Connor
Sep 25 '18 at 13:08













try putting it in viewDidLayoutSubviews or layoutSubviews if using UIViewController and UIView sub-classes respectively.

– ChanOnly123
Sep 25 '18 at 13:09





try putting it in viewDidLayoutSubviews or layoutSubviews if using UIViewController and UIView sub-classes respectively.

– ChanOnly123
Sep 25 '18 at 13:09













I can't imagine you will use this styling cue in more than one or two view controllers and to extend UIView, the building block of UIKit, the ultimate superclass, for this is IMO not a decision that I would make. This would be much better handled by using an asset, like a PNG. If you're doing an animation that adjusts the radius, like a pull-to-refresh, I still wouldn't extend UIView for that, I'd keep it as local as possible.

– bsod
Mar 28 at 18:45






I can't imagine you will use this styling cue in more than one or two view controllers and to extend UIView, the building block of UIKit, the ultimate superclass, for this is IMO not a decision that I would make. This would be much better handled by using an asset, like a PNG. If you're doing an animation that adjusts the radius, like a pull-to-refresh, I still wouldn't extend UIView for that, I'd keep it as local as possible.

– bsod
Mar 28 at 18:45













1 Answer
1






active

oldest

votes


















0
















You can use Layer.corner.Radius on the orange view.



First put that view width bigger than the super view:



@IBOutlet weak var orangeView: UIView!

self.orangeView.frame. width = self.view.frame + 50
self.orangeView.layer.corner.Radius = self.orangeView.frame.height /2





share|improve this answer





























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52495806%2frounded-curve-edge-for-uiview%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0
















    You can use Layer.corner.Radius on the orange view.



    First put that view width bigger than the super view:



    @IBOutlet weak var orangeView: UIView!

    self.orangeView.frame. width = self.view.frame + 50
    self.orangeView.layer.corner.Radius = self.orangeView.frame.height /2





    share|improve this answer































      0
















      You can use Layer.corner.Radius on the orange view.



      First put that view width bigger than the super view:



      @IBOutlet weak var orangeView: UIView!

      self.orangeView.frame. width = self.view.frame + 50
      self.orangeView.layer.corner.Radius = self.orangeView.frame.height /2





      share|improve this answer





























        0














        0










        0









        You can use Layer.corner.Radius on the orange view.



        First put that view width bigger than the super view:



        @IBOutlet weak var orangeView: UIView!

        self.orangeView.frame. width = self.view.frame + 50
        self.orangeView.layer.corner.Radius = self.orangeView.frame.height /2





        share|improve this answer















        You can use Layer.corner.Radius on the orange view.



        First put that view width bigger than the super view:



        @IBOutlet weak var orangeView: UIView!

        self.orangeView.frame. width = self.view.frame + 50
        self.orangeView.layer.corner.Radius = self.orangeView.frame.height /2






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 28 at 18:36









        double-beep

        3,1977 gold badges19 silver badges33 bronze badges




        3,1977 gold badges19 silver badges33 bronze badges










        answered Mar 28 at 18:18









        Roliandro BarbosaRoliandro Barbosa

        1




        1

































            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52495806%2frounded-curve-edge-for-uiview%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript