Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 什么';在UIKit中创建透明线的最快方法是什么?_Iphone_Ios_Uikit_Core Graphics - Fatal编程技术网

Iphone 什么';在UIKit中创建透明线的最快方法是什么?

Iphone 什么';在UIKit中创建透明线的最快方法是什么?,iphone,ios,uikit,core-graphics,Iphone,Ios,Uikit,Core Graphics,这个: UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, 1)]; view.backgroundColor = [UIColor whiteColor]; view.alpha = 0.1; 或者这个: UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, 1)]; view.backgroundColor = [UICo

这个:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, 1)];
view.backgroundColor = [UIColor whiteColor];
view.alpha = 0.1;
或者这个:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, 1)];
view.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.1];

或者还有第三种选择吗?是否将UIImageView与图像一起使用?使用CoreGraphics进行自定义绘图?什么应该是最快的?

最快的方法是创建CALayer。如果需要,使用此选项可以轻松更改其颜色/不透明度

CALayer *line = [CALayer new];
line.frame = CGRectMake(x, y, width, 1.0);
line.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1].CGColor;
[someView.layer addSublayer:line];
如果要在现有视图上绘制一条直线,并使其保持不变,则可以将以下代码添加到现有视图的drawRect:方法中:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [[UIColor whiteColor] colorWithAlphaComponent:0.1].CGColor);
CGContextSetLineWidth(context, 1.0);
CGContextMoveToPoint(context, x, y);
CGContextAddLineToPoint(context, x + width, y);
CGContextStrokePath(context);

我不知道什么是最快的,但您可能希望在测试中包括NSBezierPath,因为这是一些苹果示例代码用于简单的线条绘制。您是否尝试过使用CALayer?这是一个更轻的对象,可以查看UIView并使用更少的内存。我怀疑它会比UIView画得更快。你只是想画这条线,还是以后需要对这条线做很多操作?不需要操作。只需设置颜色及其alpha/不透明度。