0

banner of this image

I'm creating a profile view like this but how to create background banner image like this? this banner image will be dynamic.

Anand Suthar
  • 3,678
  • 2
  • 30
  • 52

3 Answers3

0

The best way to do this is to create a subclass of UIImageView or even a UIView that will contain the image (for this one remember to clip subviews) and override this method:

- (void)drawRect:(CGRect)rect

You can find an example here where he makes an UIView with the shape of a Circle. : How to draw a custom UIView that is just a circle - iPhone app

- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextAddEllipseInRect(ctx, rect);
    CGContextSetFillColor(ctx, CGColorGetComponents([[UIColor blueColor] CGColor]));
    CGContextFillPath(ctx);
}

With this information you can proceed to make other shapes like this: Drawing a polygon with one color for stroke, and a different one for fill?

So get these examples, and shape your view the way you want.

Community
  • 1
  • 1
Roberto Ferraz
  • 2,511
  • 24
  • 43
0
  you can iverride drwarect method in image view code for hardcoded value for iphone 4 
 - (void)drawRect:(CGRect)rect
    {
            CGContextRef context = UIGraphicsGetCurrentContext();
            CGMutablePathRef a_path = CGPathCreateMutable();
            CGContextBeginPath(context);
        CGContextSetLineWidth(context, 3);

        // Draw the polygon
        CGContextMoveToPoint(context, 0, 0);
        CGContextAddLineToPoint(context, 320, 0); // base
        CGContextAddLineToPoint(context, 320, 80); // right border
        CGContextAddLineToPoint(context, 0, 120);
        CGContextAddLineToPoint(context, 0, 0);


        // Stroke it
        CGContextClosePath(context);
        CGContextAddPath(context, a_path);
        // Fill it
        CGContextSetRGBFillColor(context, (0/255.0), (0/255.0), (0/255.0), 0);
        //CGContextFillPath(context);

            CGContextFillPath(context);
            CGPathRelease(a_path);

    }
SHEBIN
  • 163
  • 1
  • 10
0

currently I do this for UIImageView in category.

CAShapeLayer *mask=[CAShapeLayer new];
mask.frame=self.layer.bounds;
CGMutablePathRef path = CGPathCreateMutable();
CGFloat width = self.layer.frame.size.width;
CGFloat height = self.layer.frame.size.height;

CGPathMoveToPoint(path, nil, 0, 0);
CGPathAddLineToPoint(path, nil, width, 0);
CGPathAddLineToPoint(path, nil, width, height);
CGPathAddLineToPoint(path, nil, 0, height/2);
CGPathAddLineToPoint(path, nil, 0, 0);
CGPathCloseSubpath(path);

mask.path = path;
CGPathRelease(path);

self.layer.mask = mask;

CAShapeLayer *shape = [CAShapeLayer layer];
shape.frame = self.bounds;
shape.path = path;
shape.lineWidth = 3.0f;
shape.strokeColor = [UIColor whiteColor].CGColor;
[self.layer insertSublayer: shape atIndex:0];