zoukankan      html  css  js  c++  java
  • weChat聊天发送图片带有小尖角的实现

    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.}
    • 实现效果
      Alt text
     
  • 相关阅读:
    centos 新增用户, 然后他在主目录添加网站403Forbbiden
    linux 把用户加入一个组&从这个组中移除
    [THINKPHP] 温故知新之getFieldBy
    php 获取指定月份的开始结束时间
    apache 占用内存总量与每个apache进程的平均内存占用量计算
    网站并发300就很慢
    centos定时备份数据库超简单示例
    php导出excel时间错误(同一个时间戳,用date得到不同的时间)
    设置iframe 载入页面的效果跟直接打开这个页面一样
    node基础09:第2个node web服务器
  • 原文地址:https://www.cnblogs.com/buakaw/p/5282067.html
Copyright © 2011-2022 走看看