Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, the Bounty is gone, but I want to contribute another answer. You will find a working project at github: <a href="https://github.com/vikingosegundo/PlectrumView" rel="nofollow noreferrer">https://github.com/vikingosegundo/PlectrumView</a></p> <pre><code>#import "PlectrumView.h" @implementation PlectrumView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { } return self; } -(void) drawPlectrumWithPercentage:(CGFloat) percentage color:(UIColor *)color { CGFloat factor = self.frame.size.width ; percentage*=factor; UIBezierPath* plectrum = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(0, factor - percentage, percentage,percentage) byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii: CGSizeMake(percentage/2, percentage/2)]; [color setFill]; [plectrum fill]; } - (void)drawRect:(CGRect)rect { [self drawPlectrumWithPercentage:1.0 color:[UIColor colorWithWhite:.9 alpha:1]]; [self drawPlectrumWithPercentage:.75 color:[UIColor colorWithRed:245.0/255.0 green:134.0/255.0 blue:122.0/255.0 alpha:1]]; [self drawPlectrumWithPercentage:.61 color:[UIColor colorWithRed:171.0/255.0 green:212.0/255.0 blue:105.0/255.0 alpha:1]]; } @end </code></pre> <p>Results in</p> <p><img src="https://i.stack.imgur.com/UZzgl.png" alt="enter image description here"></p> <hr> <p>edit:</p> <p>I change the plectrum code in a way that it's area will represent the percentage instead of it's width. It feels more natural.</p> <p><img src="https://i.stack.imgur.com/7tobb.png" alt="plectrum new"></p> <pre><code>-(void) drawPlectrumWithPercentage:(CGFloat) percentage color:(UIColor *)color { static CGFloat pi = 3.141592653589793; static CGFloat radius100percent = 50.0; static CGFloat area100percent; static CGFloat threeFouthPiPlusOne; area100percent= radius100percent * radius100percent * pi *3/4 + radius100percent*radius100percent; threeFouthPiPlusOne = (1 + (pi*(3.0/4.0))); CGFloat area = area100percent * percentage; CGFloat newRadius = sqrt(area / threeFouthPiPlusOne); percentage = newRadius/ 50.0; CGFloat factor = self.frame.size.width ; percentage*=factor; UIBezierPath* plectrum = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(0, factor - percentage, percentage,percentage) byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii: CGSizeMake(percentage/2, percentage/2)]; [color setFill]; [plectrum fill]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload