我已經在滾動視圖邊境需要
創建一個六邊形的圖像programitically一個programitically創建六角圖片,我想圍繞着六邊形的圖像,形狀爲一個六邊形的同一個黑色邊框。我以六角形圖像作爲背景,但我沒有得到結果。任何人都可以指導我如何獲得理想的結果?
以下是創建六邊形的代碼圖像 -
-(CAShapeLayer*)ChangeShape:(UIView*)view
{
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(_TopList_ImageView.frame.origin.x, _TopList_ImageView.frame.origin.y, _TopList_ImageView.frame.size.width, _TopList_ImageView.frame.size.height)];
// v.backgroundColor = [UIColor purpleColor];
CGRect rect = v.frame;
CAShapeLayer *hexagonMask = [CAShapeLayer layer];
CAShapeLayer *hexagonBorder = [CAShapeLayer layer];
hexagonBorder.frame = v.layer.bounds;
UIBezierPath *hexagonPath = [UIBezierPath bezierPath];
CGFloat sideWidth = 2 * (0.5 * rect.size.width/2);
CGFloat lcolumn = (rect.size.width - sideWidth)/2;
CGFloat rcolumn = rect.size.width - lcolumn;
CGFloat height = 0.866025 * rect.size.height;
CGFloat y = (rect.size.height - height)/2;
CGFloat by = rect.size.height - y;
CGFloat midy = rect.size.height/2;
CGFloat rightmost = rect.size.width;
[hexagonPath moveToPoint:CGPointMake(lcolumn, y)];
[hexagonPath addLineToPoint:CGPointMake(rcolumn, y)];
[hexagonPath addLineToPoint:CGPointMake(rightmost, midy)];
[hexagonPath addLineToPoint:CGPointMake(rcolumn, by)];
[hexagonPath addLineToPoint:CGPointMake(lcolumn, by)];
[hexagonPath addLineToPoint:CGPointMake(0, midy)];
[hexagonPath addLineToPoint:CGPointMake(lcolumn, y)];
hexagonMask.path = hexagonPath.CGPath;
hexagonBorder.path = hexagonPath.CGPath;
hexagonBorder.fillColor = [UIColor clearColor].CGColor;
hexagonBorder.strokeColor = [UIColor blackColor].CGColor;
hexagonBorder.lineWidth = 5;
v.layer.mask = hexagonMask;
[v.layer addSublayer:hexagonBorder];
// hexagonMask.path = path.CGPath;
UIGraphicsEndImageContext();
return hexagonMask;
}
你是如何創建六邊形圖像的?使用drawRect?顯示相關代碼 –
你能展示如何獲得六角形圖像嗎? –
我上面貼的代碼可以查看@ balkaran singh – pri