weChat聊天发送图片带有小尖角的实现

1.#import <UIKit/UIKit.h>
2.
3.@interface JKShapeImage : UIView
4.
5.@property (nonatomic,strong) UIImage *image;
6.
7.@property (nonatomic,getter=isOnLeft,assign) BOOL onLeft;
8.
9.@end
1.#import "JKShapeImage.h"
2.
3.@interface JKShapeImage ()
4.{
5. CAShapeLayer *maskLayer;
6. CALayer *contentLayer;
7.}
8.@end
9.
10.@implementation JKShapeImage
11.
12.-(instancetype)initWithFrame:(CGRect)frame{
13. if (self = [super initWithFrame:frame]) {
14. [self setShapeMask];
15. }
16. return self;
17.}
18.
19.-(void)setFrame:(CGRect)frame{
20. [super setFrame:frame];
21.}
22.
23.-(void)setShapeMask{
24. maskLayer = [CAShapeLayer layer];
25. maskLayer = [CAShapeLayer layer];
26. maskLayer.fillColor = [UIColor blackColor].CGColor;
27. maskLayer.strokeColor = [UIColor clearColor].CGColor;
28. maskLayer.frame = self.bounds;
29. maskLayer.contentsCenter = CGRectMake(0.65, 0.65, 0.2, 0.2);
30. maskLayer.contentsScale = [UIScreen mainScreen].scale; //非常关键设置自动拉伸的效果且不变形
31.
32. CGFloat w = self.bounds.size.width;
33. CGFloat h = self.bounds.size.height;
34.
35. UIBezierPath *path = [UIBezierPath bezierPath];
36. if (self.isOnLeft) {
37. [path moveToPoint:CGPointMake(9, 0)];
38. [path addLineToPoint:CGPointMake(w, 0)];
39. [path addLineToPoint:CGPointMake(w, h)];
40. [path addLineToPoint:CGPointMake(9, h)];
41. [path addLineToPoint:CGPointMake(9, 25)];
42. [path addLineToPoint:CGPointMake(0, 20)];
43. [path addLineToPoint:CGPointMake(9, 15)];
44. [path addLineToPoint:CGPointMake(9, 0)];
45. }else{
46. [path moveToPoint:CGPointMake(0, 0)];
47. [path addLineToPoint:CGPointMake(w - 9, 0)];
48. [path addLineToPoint:CGPointMake(w - 9, 15)];
49. [path addLineToPoint:CGPointMake(w, 20)];
50. [path addLineToPoint:CGPointMake(w - 9, 25)];
51. [path addLineToPoint:CGPointMake(w - 9, h)];
52. [path addLineToPoint:CGPointMake(0, h)];
53. [path addLineToPoint:CGPointMake(0, 0)];
54. }
55. maskLayer.path = path.CGPath;
56.
57.
58. contentLayer = [CALayer layer];
59. contentLayer.mask = maskLayer;
60. contentLayer.frame = self.bounds;
61. [self.layer addSublayer:contentLayer];
62.
63.}
64.
65.-(void)setImage:(UIImage *)image{
66. _image = image;
67. contentLayer.contents = (__bridge id)image.CGImage;
68.}
  • 实现效果
 

最新文章

  1. LDO和DC-DC器件的区别
  2. Js设置及获取Cookie的方法
  3. PCL中的类
  4. 《算法设计手册》面试题解答 第五章:图的遍历 附:DFS应用之找挂接点
  5. linux下登陆用户的行为信息—w和who命令详解
  6. 【python】闰年规则
  7. ionic安装
  8. 全平台网页播放器兼容H5与Flash还带播放列表
  9. Java Spring Boot VS .NetCore (一)来一个简单的 Hello World
  10. 使用golang求出A-Z的所有子集
  11. HTML —— 小记
  12. 【2017-2-20】C#运算符
  13. 【go】http实验
  14. vue 内引入jquery
  15. springboot-33-使用maven打瘦包
  16. 【LeetCode】115. Populating Next Right Pointers in Each Node (2 solutions)
  17. Gradle sync failed: Read timed out
  18. DMA(Direct Memory Access)简介
  19. http://deepdish.io/2015/04/28/creating-lmdb-in-python/
  20. Python开发基础-Day30多线程锁机制

热门文章

  1. 【HDOJ】4109 Instrction Arrangement
  2. wcf客户端捕获异常
  3. 5个最佳免费Linux杀毒软件
  4. 详解Linux配置iSCSI方法
  5. (转载)shell中用date命令获取昨天、明天或者多天前的日期
  6. [SSD大法好]神舟K480-I5-D3鸟枪换炮M6S
  7. 《Linear Algebra and Its Applications》-chaper4-向量空间-子空间、零空间、列空间
  8. codeforces A. Jeff and Rounding (数学公式+贪心)
  9. mysql 导出,导入数据
  10. JUnit-4.11使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误