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 1047287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:16:38+00:00 2026-05-16T16:16:38+00:00

I have a view with a scrollview. I use code to add labels to

  • 0

I have a view with a scrollview. I use code to add labels to the scrollview. Since there’s a lot of redundant code, I tried to move the label creation to a separate function that returns a UILabel. Here’ that function:

- (UILabel *)   f_MakeLabelWithL:(float)MyLeft T:(float)MyTop W:(float)MyWidth H:(float)MyHeight Align:(UITextAlignment)MyAlign 
                      Font:(UIFont *)MyFont TextColor:(UIColor *)MyTextColor BGColor:(UIColor *)MyBGColor {

CGRect rect = CGRectMake(MyLeft, MyTop, MyWidth, MyHeight);
UILabel *label = [[[UILabel alloc] initWithFrame:rect] autorelease];

label.adjustsFontSizeToFitWidth = YES;
label.backgroundColor = MyBGColor;
label.font = MyFont;
label.numberOfLines = 0;
label.textAlignment = MyAlign;
label.textColor = MyTextColor;

return label;
}

I set the text of the label after it is returned. Or so I intended. In fact, a label that is told to have a blue background appears as a solid black rectangle. One with a clear background is entirely clear. Worse than that: the scrollview won’t scroll, and attempting to make it do so crashes the app without any explanation in the debugger console.

Yet all this code works inline just fine and dandy.

Anyone know why?

Update: Putting the code inline fixed the display of the labels. But I was also using a function to create images:

- (UIImageView *) f_MakeImageWithL:(float)MyLeft T:(float)MyTop W:(float)MyWidth H:(float)MyHeight File:(NSString *)MyFile {
CGRect rect = CGRectMake(MyLeft, MyTop, MyWidth, MyHeight);
UIImageView *oImageView = [[[UIImageView alloc] initWithFrame:rect] autorelease];

NSString *s = [[Isystant f_DocumentsPath] stringByAppendingPathComponent:MyFile];
UIImage *oImage = [UIImage imageWithContentsOfFile:s];
[oImageView setImage:oImage];
oImageView.backgroundColor = [UIColor redColor];
oImageView.opaque = YES; // explicitly opaque for performance

return oImageView;
}

It was creating the images, but the frozen scroll/crash problem didn’t go away until I put this code back inline also.

  • 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-16T16:16:39+00:00Added an answer on May 16, 2026 at 4:16 pm

    Looks to me like you are over-releasing the UILabel. You shouldn’t have to release the label after adding it to your scrollview if it was never retained anywhere prior to that (and you’ve autoreleased it in the makeImageWithL method).

    That’s probably why it is working when you put it inline… because in that scenario, I would bet you are removing the autorelease, right?

    -S

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

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You only need one table for tax percentages: CDN_TAXES tax_id… May 16, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer Try stringByReplacingOccurrencesOfString:withString:. NSString* foo = @"axvc abc amamam dff abc… May 16, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer It is feasible, sure. You should add and start the… May 16, 2026 at 5:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have view which contains a scrollView. When the view shows up the image
I use the following code to load an image into an scroll view. The
i have a scroll view which represents a map, it has pins on it,
I've seem to implement all the right code here. Is there something I'm missing
Setup: Tab Bar App First View is a ScrollView which has an ImageView as
I have subclassed View and do some bitmap drawing inside of the onDraw method.
I have a world view, so to speak, that consists of a large, zoomable
Please help! I define a custom UIControl with three labels, then on the viewDidLoad
I am a noob at OBJ-C :) I am trying to add a UIImageView
I'm attempting to setup a scrollview with infinite (horizontal) scrolling. Scrolling forward is easy

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.