Rounded cornered with colored border for a rectangle

Discussion in 'iOS Programming' started by mpramodjain, Nov 15, 2011.

  1. mpramodjain macrumors regular

    Joined:
    Nov 20, 2008
    Location:
    Banglore
    #1
    Can it be possible to draw the rounded rectangle with colored corner without using stroke and clipping concept?
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Import "QuartzCore", and add
    Code:
    object.layer.cornerradius = 15.0;
    
    about the color, i'll leave the searching for you ;)
    i'll give you some hints.
    Also Quartzcore & here are some hints
    Code:
        object.layer.borderWidth = 2.0;
        CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB();
        CGFloat values[4] = {1.0, 1.0, 1.0, 0.3}; 
        CGColorRef white = CGColorCreate(rgbColorspace, values); 
    
    Now you need to assign this to your object (the color) and release the colors, cuz it's leaking right now ;) have fun.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Here's a one-liner alternative to generating CGColor:
    Code:
    CGColorRef white = [[UIColor colorWithWhite:1.0 alpha:0.3] CGColor];
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    Dejo, you're a Demi god, but to me, you're a god x)
    Thanks man.
     
  5. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #5
    This works, and if drawing a rounded-rectangle with Quartz is not an option for some reason, this can be used. However, doing this kind of work with Core-Animation properties introduces performance hits because of some subtle compositing and rendering issues. In many cases, you will have better performance if you just use Quartz and draw the border directly in a custom view.
     
  6. mpramodjain thread starter macrumors regular

    Joined:
    Nov 20, 2008
    Location:
    Banglore
    #6
    Thanks for all your replies.

    What I observed is, going with layer property change, will draw the colored border (line) over the subviews also.

    For eg : if we draw a UIView (with rounded layer cornered, using layer property and larger width) , with a subview of text box. Then the border gets drawn over the textbox view also.

    If I go with some coregraphics (i tried using stroke and clipping previous), found the border doesn't gets override.

    So what I am trying is , draw rounded, colored border for an UIView with following are my points to consider :

    i) without using clipping and stroking , as it will clip the other part of the bordered stroke.
    ii) without modifying internal layer of the view object, as it will override the colored border on the internal successive subviews if the border width exceeds for some reason (change in design)..

    Trying using insets for the multiple rectangles and changing the color .. the other way around.. will update..
     

Share This Page