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

            How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

            Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?