在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:
方法中。