Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.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
在iOS故事板中绘制类似于Android的线条';s的XML行_Ios_Uiview_Line_Uistoryboard - Fatal编程技术网

在iOS故事板中绘制类似于Android的线条';s的XML行

在iOS故事板中绘制类似于Android的线条';s的XML行,ios,uiview,line,uistoryboard,Ios,Uiview,Line,Uistoryboard,在安卓系统中,我可以通过简单地创建一个视图并设置其背景色来画线 <LinearLayout...> ... <View android:layout_width="1dp" android:layout_height="match_parent" android:background="@color/black" ... <View android:layout_width="match_parent" android:layout_height="2dp"

在安卓系统中,我可以通过简单地创建一个视图并设置其背景色来画线

<LinearLayout...>
...
<View android:layout_width="1dp"
  android:layout_height="match_parent"
  android:background="@color/black"
...
<View android:layout_width="match_parent"
  android:layout_height="2dp"
  android:background="@color/red"
...
</LinearLayout>

...

您可以创建一个通用的
ui视图
,并在情节提要中将其
宽度
高度
设置为1磅。将其
backgroundColor
设置为您想要的行。请确保您设置了它的约束或调整大小的掩码,以便在调整屏幕大小时,它的宽度/高度不会增加。

同样的事情。使用宽度较小的
ui视图
,并将其背景色设置为所需颜色

 UIView *lineView = [[UIView alloc]init];
 lineView.frame = CGRectMake(0,50,self.View.frame.size.width,1);
 lineView.backgroundColor = [UIColor blackColor];
 [self.view addSubview:lineView];
以代码创建的这个简单视图为例,只需将其高度调整1或2 就像上面的代码->lineView.frame=CGRectMake(,);
CGFloat高度取1

//以在uiview类中绘制线

 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextSetLineWidth(context, 1.0);
 CGContextSetStrokeColorWithColor(context, [[UIColor whiteColor]   CGColor]);
 CGContextMoveToPoint(context, xstartPoint, yStart);
 CGContextAddLineToPoint(context, xstartPoint, yBottom);
 CGContextStrokePath(context);
 CGContextSaveGState(context);

我看到了反对票。但我不想假设安卓系统的答案就是iOS系统的答案:我发现iOS系统比安卓系统更友好、更完整——说得委婉一点。这需要解释。这段代码大概位于UIView的自定义子类的
drawRect:
方法中。