【发布时间】:2018-09-04 11:42:28
【问题描述】:
我正在尝试 AspectFit 基于 UIBezierPath 的自定义按钮。
这是我在自定义类中的代码,它是 UIButton 类的子类
-(id)initWithCoder:(NSCoder *)coder {
if (self = [super initWithCoder:coder]) {
self.contentMode = UIViewContentModeScaleAspectFill;
}
return self;
}
-(void)drawRect:(CGRect)rect {
UIColor* fillColor = [UIColor colorWithRed: 0.451 green: 0.855 blue: 1 alpha: 1];
UIBezierPath* clipPath = [UIBezierPath bezierPathWithRect: CGRectMake(0, 0.01, 81.6, 40.9)];
[clipPath addClip];
UIBezierPath* bezierPath = [UIBezierPath bezierPath];
[bezierPath moveToPoint: CGPointMake(81.21, 13.63)];
[bezierPath addCurveToPoint: CGPointMake(48.11, 40.91) controlPoint1: CGPointMake(84.3, 37.04) controlPoint2: CGPointMake(68.27, 40.91)];
[bezierPath addCurveToPoint: CGPointMake(4.72, 45.04) controlPoint1: CGPointMake(33.83, 40.91) controlPoint2: CGPointMake(3.32, 40.91)];
[bezierPath addCurveToPoint: CGPointMake(20.19, 7.94) controlPoint1: CGPointMake(-1.03, 14.37) controlPoint2: CGPointMake(-1.26, 0.28)];
[bezierPath addCurveToPoint: CGPointMake(81.21, 13.63) controlPoint1: CGPointMake(40.97, 1.57) controlPoint2: CGPointMake(78.62, -6.04)];
[bezierPath closePath];
[fillColor setFill];
[bezierPath fill];
}
在 xib 中,我将自定义类分配给 UIButton 对象。我尝试在 IB 中使用 AspectFit 处理程序,并在 initWithCoder 中尝试过,但似乎没有任何效果。
【问题讨论】:
标签: ios objective-c uibezierpath