Resolved Why is it that I can make two labels overlap and still be partially visible?

Discussion in 'iOS Programming' started by moonman239, Feb 22, 2014.

  1. moonman239, Feb 22, 2014
    Last edited: Apr 7, 2014

    moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    When I place Alice over Bob, depending on Bob's text and location, I can see some of Bob's text, no matter how far into Alice's frame Bob's text is. Why?
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    Likely because the label background is clear. Play with the following code to see a sample. I've set the text color and border to help display highlight the result.

    Code:
        CGRect lableRect = CGRectMake(20.0, 250.0, 50.0, 22.0);
        UILabel * bob = [[UILabel alloc] initWithFrame: lableRect];
        bob.layer.borderColor = [[UIColor redColor] CGColor];
        bob.textColor = [UIColor redColor];
        bob.layer.borderWidth = 1.0;
        bob.text = @"Bob";
        
        lableRect = CGRectMake(40.0, 250.0, 50.0, 22.0);
        UILabel * alice = [[UILabel alloc] initWithFrame: lableRect];
        alice.layer.borderColor = [[UIColor blueColor] CGColor];
        alice.layer.borderWidth = 1.0;
        alice.text = @"Alice";
        alice.textColor = [UIColor blueColor];
        alice.backgroundColor = [UIColor clearColor];
        
        [self.view addSubview: bob];
        [self.view addSubview: alice];
    
     
  3. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #3
    Thank you!
     

Share This Page