【发布时间】:2016-11-07 09:48:03
【问题描述】:
我使用下一个代码:
- (void)setMaskByRoundingCorners:(UIRectCorner)corners withCornerRadius:(float)radius
{
UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer* shape = [[CAShapeLayer alloc] init];
[shape setPath:rounded.CGPath];
shape.frame = self.bounds;
self.layer.mask = shape;
}
但现在我看到了这种奇怪的效果。
我从 viewcontroller 调用它,在 didlayoutsubviews 之后。我这样做是为了更新主线程。
- (void)viewDidLayoutSubviews
{
[self initUIfeatures];
}
- (void)initUIfeatures
{
[authTextField setMaskByRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft) withCornerRadius:8.0f];
}
问题是圆角被截断。
【问题讨论】:
-
你为什么不使用 layer.corner.raius 来做呢?
-
你从哪里调用这个方法?
-
@alexburtnik - (void)viewDidLayoutSubviews { [self initUIfeatures]; } - (void)initUIfeatures { [authTextField setMaskByRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft) withCornerRadius:8.0f]; }
-
@ZaidPathan 它不是重复的!我的问题是文本字段而不是简单的 UIView。我将我的函数用于 uiview 的所有其他孩子,它工作正常,但这里我有一个错误。
-
@Viktorianec,给定的源代码有效吗?
标签: ios interface textfield quartz-core