大家好,我需要實現像這些UIImageView
的邊框。UIImageView邊和頂部圓角邊框
左側,頂部和右邊界像一個半月
http://imageshack.com/a/img841/3269/o90p.png
我該怎麼辦呢?
大家好,我需要實現像這些UIImageView
的邊框。UIImageView邊和頂部圓角邊框
左側,頂部和右邊界像一個半月
http://imageshack.com/a/img841/3269/o90p.png
我該怎麼辦呢?
您需要:
CAShapeLayer
view.bounds
但只有兩個圓角的CGPathRef
(可能通過使用[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]
)CAShapeLayer
只要考慮到這會對性能產生不良影響。 This might help
你可以用戶CALayer
相同。
CALayer *l = [_btn layer];
[l setMasksToBounds:YES];
[l setCornerRadius:8.0];
,並添加QuartzCore.framework
你可能想繼承UIView
並重寫drawRect:
方法。然後將您的圖像視圖添加爲子視圖。你drawRect:
方法會是這個樣子(與clipsToBounds
設置爲YES
):
- (void)drawRect:(CGRect)rect
{
UIColor *fillColor = [UIColor clearColor];
UIColor *borderColor = [UIColor redColor];
float borderWidth = 2.0f;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, fillColor.CGColor);
CGContextSetLineWidth(context, borderWidth);
CGContextSetStrokeColorWithColor(context, borderColor.CGColor);
CGContextMoveToPoint(context, CGRectGetMinX(rect), CGRectGetMidY(rect));
CGContextAddArc(context, CGRectGetMidX(rect), CGRectGetMidY(rect), rect.size.height/2, 2*M_PI, M_PI, 1);
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke);
}
或者你可以看看與半圓圖像屏蔽或創建圖像視圖CAShapeLayer
。
這應該幫助http://stackoverflow.com/questions/13153223/how-to-crop-the-image-using-uibezierpath – Avt