Where to write code to draw a square in UITableViewCell on iPhone

I have the following code to draw a square outline with the following code.

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToRect(context, CGRectMake(0.0, 00.0, 50, 50));
CGContextSetLineWidth(context, 3.0);
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextStrokeRect(context, CGContextGetClipBoundingBox(context));

I want to draw this square in a UITableViewCell. So where should I write cocde to draw a square in this cell. I want to draw

+3
source share
1 answer

This code can be written to the cellForRowAtIndexPath method for the table.

I wrote the following code to add two labels to my table.

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
   static NSString *cellId=@"Cell";
   UITableViewCell *cell=[tableView dequeReusableCellWithIdentifier:cellId];

   if(cell==nil)
   {
       cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
   }

   // you can put down you logic of customizing your cell here.
   //for example see mine code.

   CGRect frm1=CGRectMake(10,10,290,25);
   UILabel *lbTmp;
   lbTmp=[[UILabel alloc] initWithFrame: frm1];
   lblTmp.text=@"something something"
   cell.contentView addSubview:lb1Tmp];
   [lblTmp release];
   return cell;
}
0
source

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


All Articles