Only one of these subviews is being shown
-
21-12-2019 - |
Question
I am passing 2 imageviews to the next view using a segue and only one of the images is being shown. I can't find a fix for this anywhere.
Code for the segue:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqual:@"CloudyBlue"]) {
Level1_4inch_White *dest = [segue destinationViewController];
CloudyBlue.frame = CGRectMake(78, 277, 139, 100);
CloudyBlue1.frame = CGRectMake(363, 277, 139, 100);
[dest.view addSubview:CloudyBlue];
[dest.view addSubview:CloudyBlue1];
}
}
UPDATE: As to one of the comments, here is what It looks like: There is suppose to be another eye on the left.
EDIT:
@interface WeatherEyeViewController_4inch_White : UIViewController {
IBOutlet UIImageView *CloudyBlue;
IBOutlet UIImageView *CloudyBlue1;
}
I figured it out! Instead of creating it like above. I create them like this and it works!
UIImageView *CloudyBlue = [[UIImageView alloc] initWithFrame:CGRectMake(78, 277, 139, 100)];
UIImageView *CloudyBlue1 = [[UIImageView alloc] initWithFrame:CGRectMake(363, 277, 139, 100)];
[CloudyBlue setImage:[UIImage imageNamed:@"Cloudy-Eye-Blue.png"]];
[CloudyBlue1 setImage:[UIImage imageNamed:@"Cloudy-Eye-Blue.png"]];
Solution 2
I figured it out! Instead of creating it like above. I create them like this and it works!
UIImageView *CloudyBlue = [[UIImageView alloc] initWithFrame:CGRectMake(78, 277, 139, 100)];
UIImageView *CloudyBlue1 = [[UIImageView alloc] initWithFrame:CGRectMake(363, 277, 139, 100)];
[CloudyBlue setImage:[UIImage imageNamed:@"Cloudy-Eye-Blue.png"]];
[CloudyBlue1 setImage:[UIImage imageNamed:@"Cloudy-Eye-Blue.png"]];
OTHER TIPS
Don't hardcore the frames using CGRectMake
. Instead you should be setting the frames in the storyboard, or, rather, setting the frames by specifying the auto-layout constraints. By using auto-layout your views will change is suitable ways when the interface is rotated.