0
A
回答
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);
}
相关问题
- 1. 创建这种类型
- 2. 如何使用coordinatorLayout,AppbarLayout,CollaspingToolbarLayout创建这种类型的布局
- 3. 如何创建这种类型的菜单和所有结构
- 4. 如何创建这种类型的段落
- 5. 如何使用XHTML&CSS创建这种类型的元素?
- 6. 如何创建这种类型的网站?
- 7. 如何在xml中创建这种类型的绘图
- 8. 如何正确创建这种类型的布局(包含PHP)
- 9. 如何创建这种类型的节点:<node />?
- 10. 如何在javascript中创建这种类型的数组
- 11. 如何从PHP创建这种类型的JSON数据
- 12. 如何在android中创建这种布局类型
- 13. 如何创建这种XML?
- 14. 如何创建需要3种类型的泛型类
- 15. 如何在C#创建这三个类泛型类或类型
- 16. 如何为一种类型的对象创建一个类?
- 17. 如何在我的Android应用中创建这种类型的活动布局?
- 18. 图书馆来创建这种类型的图表?
- 19. 在Firefox插件中创建这种类型的弹出窗口?
- 20. Android:是否可以创建这种类型的圈子?
- 21. 为这种类型的日期创建正则表达式
- 22. 我可以在ZedGraph中创建这种类型的图吗?
- 23. 如何创建这种类型的子域名像Blogger.com一样飞行
- 24. 如何在Android中创建这种类型的弹出对话框?
- 25. 如何创建这种类型的纹理进度条“line-diag”(ninepatch?)?
- 26. 如何创建这种类型的滑块来打开下一个屏幕?
- 27. 给定一个ParameterizedType,我该如何创建这种类型的实例?
- 28. 如何使用这种类型的数据在Matlab中创建细胞阵列
- 29. 我该如何构建这种类型的接口
- 30. TYPO3 - 如何建立这种类型的字段?
你是什么意思动态 - 它会有移动图像?如果是这样,请使用MPMoviePlayer –
否,动态平均横幅图像将从url加载。 –
这个问题太广泛了。在作品中展示你的意见,不要指望有人写作业。 – Vive