2015-09-23 98 views
0

banner of this image如何创建这种类型的uiimageview?

我正在创建像这样的配置文件视图,但是如何创建像这样的背景横幅图像?这个横幅图片将是动态的。

+0

你是什么意思动态 - 它会有移动图像?如果是这样,请使用MPMoviePlayer –

+0

否,动态平均横幅图像将从url加载。 –

+2

这个问题太广泛了。在作品中展示你的意见,不要指望有人写作业。 – Vive

回答

0

当前我在UIImageView类别中这样做。

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]; 
0

要做到这一点,最好的方法是创建的UIImageView的子类,甚至一个UIView将包含图像(此人记得夹子视图)和重写此方法:

- (void)drawRect:(CGRect)rect 

你可以找到这是一个例子,他用一个圆形来制作UIView。 :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); 
} 

有了这些信息,你可以继续做其他的形状是这样的: Drawing a polygon with one color for stroke, and a different one for fill?

因此,获得这些例子,和塑造你的观点,你想要的方式。

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); 

    } 
相关问题