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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:18:31+00:00 2026-05-19T12:18:31+00:00

The implementation of my view is below. scrollView is an iVar of type UIScrollView.

  • 0

The implementation of my view is below. scrollView is an iVar of type UIScrollView.

The “strange behavior” is that as I scroll the view, the background gradually changes from orange to green. It seems like the almost-transparent label background is somehow stacking on itself until you end up with a green background. But I don’t understand why it would do that. Can anyone explain?

#import "ViewWithScrollView.h"

@implementation ViewWithScrollView

@synthesize scrollView;

-(void) layoutSubviews {
    scrollView.frame = self.bounds;
    CGSize size = self.frame.size;
    size.width*=2;
    size.height*=2;
    scrollView.contentSize = size;
    scrollView.backgroundColor = [UIColor orangeColor];
//  scrollView.clearsContextBeforeDrawing = YES;    //These two lines can be commented in or out; it makes no difference.
//  scrollView.opaque = NO;
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0,0,size.width, size.height)];
    label.textAlignment = UITextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:200];
    label.text = @"Princess!";
    label.textColor = [UIColor blackColor];
    label.backgroundColor = [UIColor colorWithRed:0. green:1. blue:0. alpha:0.01];
//  label.opaque = NO;  // same for these two lines
//  label.clearsContextBeforeDrawing = YES;

    [scrollView addSubview: label];
}

- (id)initWithFrame: (CGRect) frame {
    self = [super initWithFrame:frame];
    if (self) {
//      self.opaque = NO;  //again, commenting these in or out makes no difference
//      self.clearsContextBeforeDrawing = YES;
        scrollView = [[UIScrollView alloc]init];
        [self addSubview:scrollView];
    }
    return self;
}
@end
  • 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-19T12:18:32+00:00Added an answer on May 19, 2026 at 12:18 pm

    Every time -layoutSubviews is called, you’re creating a new label. This is probably happening more often than you think, and they’re piling up.

    If you’re always going to have a label in your view, go ahead and make it an instance variable. Move the creation of the label to your view’s -initWithFrame: method, alongside your scrollview. Add it as a subview there, too.

    Basically, put the stuff you want to do once (object creation, hierarchy) in -initWithFrame:, and the stuff you might need to do repeatedly because of layout changes (sizing, positioning, etc) into -layoutSubviews.

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

Sidebar

Related Questions

I want to create view like the image below. My implementation should use text
I want to create a view like image below. My implementation has some linearLayouts.
Is it impossible to present a popover controller from a view controller that's presented
Each of my Activities needs a correspoding singleton View implementation. What's the best strategy
I'm creating a new subclass of UITableViewController, and with it the below default implementation.
I have a fragment view that needs replacement with another fragment. When the ListFragment
First of all I began with the code below in my view controller but
Photo capture Intent causes NullPointerException on Samsung phones only. Implementation below. final Button capture
I'm using android listview and its working perfectly fine. my implementation as below ListView
Below is a simple example of how I'm reading from a plist and displaying

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.