Drawing strings in an iOS storyboard similar to Android XML lines

In Android, I can draw lines just by creating a view and setting its background color

<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> 

This is a common practice in Android. How can I do the same in iOS? What is the common practice? Here I see another question that tries to ask a similar question, but was told to use TableView. I am looking for something simple and general as an answer on Android.

+6
source share
4 answers

You can create a generic UIView and set its width or height to 1 pt in the storyboard. Set backgroundColor to what you want the line to be. Make sure you set your limits or resize the mask so that when you increase the screen size, it does not increase in width and height.

+23
source
  UIView *lineView = [[UIView alloc]init]; lineView.frame = CGRectMake(0,50,self.View.frame.size.width,1); lineView.backgroundColor = [UIColor blackColor]; [self.view addSubview:lineView]; 

Take this simple view created in the code and simply adjust its height to 1 or 2. Like in the code above → lineView.frame = CGRectMake (<#CGFloat x #>, <#CGFloat y #>, <#CGFloat width # >, <#CGFloat height #>); CGFloat height is taken 1

+9
source

Same. Use a small width UIView and set the background color to the desired color.

+4
source

// draw a string in the uiview class

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

Source: https://habr.com/ru/post/972052/


All Articles