overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() //UIImageVIEw let showVIEw = UIImageVIEw(frame: CGRectMake(100,100,100)) showVIEw.image = UIImage(named: "Snip20160422_3") showVIEw.layer.mask = test(showVIEw) self.vIEw.addSubvIEw(showVIEw) //UIVIEw let blankVIEw = UIVIEw(frame: CGRectMake(250,100)) blankVIEw.backgroundcolor = UIcolor.greencolor() blankVIEw.layer.mask = test(blankVIEw) self.vIEw.addSubvIEw(blankVIEw)}///把设置小三角func test(showVIEw: UIVIEw) -> CAShapeLayer { let vIEwWIDth = CGfloat(CGRectGetWIDth(showVIEw.frame)) let vIEwHeight = CGfloat(CGRectGetHeight(showVIEw.frame)) //所占的宽度,整个vIEw所占的宽度不会变,已经被制定,所以这个宽度会占用整个vIEw的宽度, let rightSpace: CGfloat = 10 //距离顶部的距离 let topSpace: CGfloat = 30 let point1 = CGPointMake(0,0) let point2 = CGPointMake(vIEwWIDth - rightSpace,0) let point3 = CGPointMake(vIEwWIDth - rightSpace,topSpace) let point4 = CGPointMake(vIEwWIDth,topSpace) let point5 = CGPointMake(vIEwWIDth - rightSpace,topSpace + 10) let point6 = CGPointMake(vIEwWIDth - rightSpace,vIEwHeight) let point7 = CGPointMake(0,vIEwHeight) let path = UIBezIErPath() path.movetoPoint(point1) path.addlinetoPoint(point2) path.addlinetoPoint(point3) path.addlinetoPoint(point4) path.addlinetoPoint(point5) path.addlinetoPoint(point6) path.addlinetoPoint(point7) let layer = CAShapeLayer() layer.path = path.CGPath return layer }}OC代码
- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; UIVIEw *blankVIEw = [[UIVIEw alloc] initWithFrame:CGRectMake(100,100)]; blankVIEw.backgroundcolor = [UIcolor redcolor]; blankVIEw.layer.mask = [self testWithVIEw:blankVIEw]; [self.vIEw addSubvIEw:blankVIEw]; UIImageVIEw *imageVIEw = [[UIImageVIEw alloc] initWithFrame:CGRectMake(250,100)]; imageVIEw.image = [UIImage imagenamed:@"Snip20160422_3"]; imageVIEw.layer.mask = [self testWithVIEw:blankVIEw]; [self.vIEw addSubvIEw:imageVIEw];}- (CAShapeLayer *)testWithVIEw:(UIVIEw *)vIEw{ CGfloat vIEwWIDth = CGRectGetWIDth(vIEw.frame); CGfloat vIEwHeight = CGRectGetHeight(vIEw.frame); CGfloat rightSpace = 10; CGfloat topSpace = 15; CGPoint point1 = CGPointMake(0,0); CGPoint point2 = CGPointMake(vIEwWIDth-rightSpace,0); CGPoint point3 = CGPointMake(vIEwWIDth-rightSpace,topSpace); CGPoint point4 = CGPointMake(vIEwWIDth,topSpace); CGPoint point5 = CGPointMake(vIEwWIDth-rightSpace,topSpace+10.); CGPoint point6 = CGPointMake(vIEwWIDth-rightSpace,vIEwHeight); CGPoint point7 = CGPointMake(0,vIEwHeight); UIBezIErPath *path = [UIBezIErPath bezIErPath]; [path movetoPoint:point1]; [path addlinetoPoint:point2]; [path addlinetoPoint:point3]; [path addlinetoPoint:point4]; [path addlinetoPoint:point5]; [path addlinetoPoint:point6]; [path addlinetoPoint:point7]; [path closePath]; CAShapeLayer *layer = [CAShapeLayer layer]; layer.path = path.CGPath; return layer;}总结
以上是内存溢出为你收集整理的Swift/OC 为View或ImageView设置聊天消息的小三角全部内容,希望文章能够帮你解决Swift/OC 为View或ImageView设置聊天消息的小三角所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)