Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7692773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:55:48+00:00 2026-05-31T20:55:48+00:00

i can draw a string/image… with drawInRect/drawAtPoint. but how about if i want to

  • 0

i can draw a string/image… with drawInRect/drawAtPoint.
but how about if i want to add a UIProgressView into this view?

I am overriding the drawRect method,

so i have to create the UIProgressView inside drawRect?


UPDATED BELOW:

Here is my UITableViewCell subclass for another class(just for showing how i did the tableViewCell subclassing) for Krumelur, I am not sure if this is correct, but this is how i usually do it.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5.0f,5.0f,40.0f,40.0f)];
//imageView.tag = kImage;
    imageView.layer.cornerRadius = 5.0;
    imageView.layer.masksToBounds = YES;

[self.contentView addSubview:imageView];



nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(55.0f, 5.0f, 220.0f, 18.0f)];
//nameLabel.tag = kName;
nameLabel.font = [UIFont boldSystemFontOfSize:16];
nameLabel.textColor = [[UIColor alloc] initWithRed:18.0/255.0 green:18.0/255.0 blue:18.0/255.0 alpha:1.0f];
    //nameLabel.textColor = [UIColor blackColor];
nameLabel.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:nameLabel];
//[nameLabel release];


    statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(55.0f, 27.0f, 220.0f, 20.0f)];
//lastMessageLabel.tag = kName;
    statusLabel.font = [UIFont systemFontOfSize:13];
statusLabel.textColor = [UIColor colorWithRed:82.0/255.0
                                            green:82.0/255.0
                                             blue:82.0/255.0
                                            alpha:0.8];;
statusLabel.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:statusLabel];
//[lastMessageLabel release];
}

return self;

}

here is how i use it in -(void)cellForRowAtIndexPath

static NSString *CellIdentifier = @"RootViewTableCell";

RootViewTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[[RootViewTableCell alloc] initWithStyle:UITableViewCellStyleDefault
                                   reuseIdentifier:CellIdentifier] autorelease];
}

//cell.backgroundView.backgroundColor = TABLE_BACKGROUND_COLOR;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

User *user = [rows objectAtIndex:indexPath.row];
cell.nameLabel.text = user.name;
cell.statusLabel.text = user.status;

if (user.photo != nil)
{
    //myUser.photo = user.photo;
    cell.imageView.image = user.photo;
} 
else{
    cell.imageView.image = [UIImage imageNamed:@"person_default"];
}
return cell;

do i have to use a tag for each of the subview? i don’t see any difference if i don’t.
do you see anything that is causing the tableview scrolling lag? because I use the same thing for my tableview before. the table datasource is from core data, and NSFetchedResultsController for any insert/delete/update, but i am sure that i store the data into a NSMutableArray as datasource, so when i scroll the tableview, there is no core data access(but still laggy). Please if you have any suggestion, i would love to hear, and i love this way more than doing UIView subclassing then override the drawRect.

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:55:49+00:00Added an answer on May 31, 2026 at 8:55 pm

    You should not draw UIProgressView in a UITableViewCell. The reason why you gain performance by overriding a UITableViewCell’s drawRect is because the device only has to composite the first frame of scrolling. The rest of the time, it’s a single opaque texture.

    Now you know why you gain performance, you can see that you can’t draw UIProgressView into drawRect, because you’re going to be updating that UIProgressView, which results in slow performance. The drawRect method is only for static content and not meant for cells that have animation.

    The best thing to do is to addSubview, but don’t add the UIProgressView as a subview in cellForRowAtIndexPath. This will result in a lot of duplicate UIProgressViews overlapping each other (due to the cell reuse).

    What you want to do is (since you’re already subclassing UITableViewCell) create a UIProgressView property in the UITableViewCell subclass, add it to the cell in the initWithStyle method, then rearrange it in the layoutSubviews.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to draw a string say stackoverflow in circular view like below image
how can I draw into an existing UIImage using monotouch? I load an image:
i want to custom view,it can include some effect:first draw a pic on the
I can draw many things using this : NSString *imagePath = [[NSBundle mainBundle] pathForResource:@dummy2.png
Any idea how I can draw Bullet Points using Flex? instead of using image
I subclassed View to get an View on which the user can draw with
I want to draw a String on some shapes following the examples in http://msdn.microsoft.com/en-us/library/aa327572%28v=vs.71%29.aspx
I want to draw a PARTIALLY transparent image on top of another (Making shadows
I want to draw a string on a picture from the library on Windows
I have a String and I want to paint it onto an image. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.