I am trying to add a UILabel anagrammatically like below
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg"]]];
[self loadAndDrawButtons];
CGRect frame = CGRectMake(357, 240, 48, 42);
CGRect frame = CGRectMake(357, 200, 48, 42);
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
[myLabel setText:@"THIS"];
[myLabel setBackgroundColor:[UIColor clearColor]];
[myLabel setTextColor:[UIColor redColor]];
[myLabel setShadowOffset:CGSizeMake(1, 1)];
[myLabel setShadowColor:[UIColor darkGrayColor]];
[self.view addSubview:myLabel];
}
So first I set the background for view and then I also display some button on the view. Background and button are successfully loaded. Eventually, I am adding a UILabel to view and I end up with nothing….
I am thinking that the background and my button will hide my UILabel( I know this is not right way but also give it a try) so that I comment out
// [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@”bg”]]];
// [self loadAndDrawButtons];
Now my view is blank without my UILable…
Could any one give my a hint about this problem…Thanks a lot
The problem likes in the label frame:
which is relative to its superview coordinates in this case your view is at the most 320 x 480 (or at least thats how much the screen can show without scrolling) however you are providing a an x value of 357 (greater than 320), which means the label is not being drawn within the visible portion of the view.