gpt4 book ai didi

ios - 边框文本域

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:13:21 25 4
gpt4 key购买 nike

我想创建圆角文本字段的边框点线。我成功地创建了一个文本字段的边框,但我有一些边框文本字段的圆角问题。我需要带虚线的圆角文本字段。这是我的代码。

firstName.layer.borderColor =[UIColor clearColor].CGColor;

border = [CAShapeLayer layer];
border.strokeColor = [UIColor blueColor].CGColor;
border.fillColor = nil;
border.lineDashPattern = @[@4, @2];
border.path = [UIBezierPath bezierPathWithRect:firstName.bounds].CGPath;
border.frame = firstName.bounds;

[firstName.layer addSublayer:border];

最佳答案

以下是去除 UITextFieldgray color 边框的解决方案。

问题

enter image description here

解决方案

enter image description here

为此,您需要使用以下一行代码 只需更改边框样式

_firstName.borderStyle = UITextBorderStyleNone;

CAShapeLayer *border = [CAShapeLayer layer];
border.strokeColor = [UIColor gray].CGColor;
border.fillColor = nil;
border.lineDashPattern = @[@4, @2];
border.path = [UIBezierPath bezierPathWithRect:_firstName.bounds].CGPath;
border.frame = _firstName.bounds;

[_firstName.layer addSublayer:border];

_firstName.borderStyle = UITextBorderStyleNone;

更新

对于圆角使用以下函数。

- (void)drawDashedBorderAroundView:(UIView *)v
{
//border definitions
CGFloat cornerRadius = 10;
CGFloat borderWidth = 2;
NSInteger dashPattern1 = 8;
NSInteger dashPattern2 = 8;
UIColor *lineColor = [UIColor orangeColor];

//drawing
CGRect frame = v.bounds;

CAShapeLayer *_shapeLayer = [CAShapeLayer layer];

//creating a path
CGMutablePathRef path = CGPathCreateMutable();

//drawing a border around a view
CGPathMoveToPoint(path, NULL, 0, frame.size.height - cornerRadius);
CGPathAddLineToPoint(path, NULL, 0, cornerRadius);
CGPathAddArc(path, NULL, cornerRadius, cornerRadius, cornerRadius, M_PI, -M_PI_2, NO);
CGPathAddLineToPoint(path, NULL, frame.size.width - cornerRadius, 0);
CGPathAddArc(path, NULL, frame.size.width - cornerRadius, cornerRadius, cornerRadius, -M_PI_2, 0, NO);
CGPathAddLineToPoint(path, NULL, frame.size.width, frame.size.height - cornerRadius);
CGPathAddArc(path, NULL, frame.size.width - cornerRadius, frame.size.height - cornerRadius, cornerRadius, 0, M_PI_2, NO);
CGPathAddLineToPoint(path, NULL, cornerRadius, frame.size.height);
CGPathAddArc(path, NULL, cornerRadius, frame.size.height - cornerRadius, cornerRadius, M_PI_2, M_PI, NO);

//path is set as the _shapeLayer object's path
_shapeLayer.path = path;
CGPathRelease(path);

_shapeLayer.backgroundColor = [[UIColor clearColor] CGColor];
_shapeLayer.frame = frame;
_shapeLayer.masksToBounds = NO;
[_shapeLayer setValue:[NSNumber numberWithBool:NO] forKey:@"isCircle"];
_shapeLayer.fillColor = [[UIColor clearColor] CGColor];
_shapeLayer.strokeColor = [lineColor CGColor];
_shapeLayer.lineWidth = borderWidth;
_shapeLayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:dashPattern1], [NSNumber numberWithInt:dashPattern2], nil];
_shapeLayer.lineCap = kCALineCapRound;

//_shapeLayer is added as a sublayer of the view, the border is visible
[v.layer addSublayer:_shapeLayer];
v.layer.cornerRadius = cornerRadius;
}

使用下面的代码调用这个函数。

_firstName.borderStyle = UITextBorderStyleNone;
[self drawDashedBorderAroundView:_firstName];

希望这对您有帮助。

关于ios - 边框文本域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33993847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com