当前位置: 动力学知识库 > 问答 > 编程问答 >

Where to write the code for drawing square in UITableViewCell in 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 into UITableViewCell. So where should I write the cocde to draw a square in that cell.

I want to draw

网友答案:

You can write this code to cellForRowAtIndexPath method for table

i have written following code to add two label in my tablecell.

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
   static NSString *[email protected]"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];
   [email protected]"something something"
   cell.contentView addSubview:lb1Tmp];
   [lblTmp release];
   return cell;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: