Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 创建具有六角的UIImage或UIImageView_Ios_Objective C_Uiimage - Fatal编程技术网

Ios 创建具有六角的UIImage或UIImageView

Ios 创建具有六角的UIImage或UIImageView,ios,objective-c,uiimage,Ios,Objective C,Uiimage,是否可以创建具有六角形角的UIImage或UIImageView?因为我想拍摄一幅UIImage,并将其显示在UIImageView中,但在内部和六边形中。谢谢过了一会儿,我找到了一个简单的实现。我创建了一个六边形视图: 六边形视图 #import <UIKit/UIKit.h> @interface HexagonView : UIView @end 结果是: 也许这可以帮助您使用这个库是的,一切都是可能的。@holex,当然,但是如何?您可以创建UIImageView的子集,

是否可以创建具有六角形角的UIImage或UIImageView?因为我想拍摄一幅UIImage,并将其显示在UIImageView中,但在内部和六边形中。谢谢

过了一会儿,我找到了一个简单的实现。我创建了一个六边形视图:

六边形视图

#import <UIKit/UIKit.h>

@interface HexagonView : UIView
@end
结果是:

也许这可以帮助您使用这个库是的,一切都是可能的。@holex,当然,但是如何?您可以创建
UIImageView
的子集,并且您可以覆盖
–drawRect:
方法,例如,使用常规六边形屏蔽实际内容,可以使用CoreGraphics.framework创建六边形屏蔽。小菜一碟。你知道怎么做它的全六角圆吗检查这个答案(好的,这是三角形,但你可以用同样的方法处理六边形)我可以添加它的边框吗?
#import "HexagonView.h"
#import <QuartzCore/QuartzCore.h>

@implementation HexagonView

- (void)drawRect:(CGRect)rect {

    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.fillRule = kCAFillRuleEvenOdd;
    maskLayer.frame = self.bounds;

    CGFloat width = self.frame.size.width;
    CGFloat height = self.frame.size.height;
    CGFloat hPadding = width * 1 / 8 / 2;

    UIGraphicsBeginImageContext(self.frame.size);
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(width/2, 0)];
    [path addLineToPoint:CGPointMake(width - hPadding, height / 4)];
    [path addLineToPoint:CGPointMake(width - hPadding, height * 3 / 4)];
    [path addLineToPoint:CGPointMake(width / 2, height)];
    [path addLineToPoint:CGPointMake(hPadding, height * 3 / 4)];
    [path addLineToPoint:CGPointMake(hPadding, height / 4)];
    [path closePath];
    [path closePath];
    [path fill];
    [path stroke];

    maskLayer.path = path.CGPath;

    UIGraphicsEndImageContext();

    self.layer.mask = maskLayer;

}

@end
[hexagonView addSubview:scaledImageView];