У меня есть UIScrollview в моем VC, содержащем 9 изображений с размером 25 пикселей x 25 пикселей на iphone 5s, они отлично расположены в центре прокрутки. при запуске на iphone 6 они сдвигаются влево, не растягиваясь равномерно по экрану, из-за размера экрана.Равномерное пространство UIImageViews в UIScrollView
Есть ли способ, которым я могу сделать их равномерно распределенными на обоих размерах экрана?
код ниже:
// Set up ScrollView NSLog(@"%f", self.view.frame.size.width); UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(25, 200, self.view.frame.size.width - 50, 30)]; scrollView.alwaysBounceHorizontal = YES; NSLog(@"%f", scrollView.frame.size.width); UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, scrollView.frame.size.width, scrollView.frame.size.height)]; [scrollView addSubview:view]; UIImage *star = [UIImage imageNamed:@"badge_star"]; UIImageView *imgView = [[UIImageView alloc] initWithImage:star]; imgView.frame = CGRectMake(2.5, 5, 25, 25); [view addSubview:imgView]; UIImage *target= [UIImage imageNamed:@"badge_target"]; UIImageView *targetImageView = [[UIImageView alloc] initWithImage:target]; targetImageView.frame = CGRectMake(32.5, 5, 25, 25); [view addSubview:targetImageView]; UIImage *crown = [UIImage imageNamed:@"badge_crown"]; UIImageView *crownImageView = [[UIImageView alloc] initWithImage:crown]; crownImageView.frame = CGRectMake(62.5, 5, 25, 25); [view addSubview:crownImageView]; UIImage *scissors = [UIImage imageNamed:@"badge_scissors"]; UIImageView *scissorsImageView = [[UIImageView alloc] initWithImage:scissors]; scissorsImageView.frame = CGRectMake(92.5, 5, 25, 25); [view addSubview:scissorsImageView]; UIImage *thumbsup = [UIImage imageNamed:@"badge_thumbs_up"]; UIImageView *thumbsupImageView = [[UIImageView alloc] initWithImage:thumbsup]; thumbsupImageView.frame = CGRectMake(122.5, 5, 25, 25); [view addSubview:thumbsupImageView]; UIImage *trophy = [UIImage imageNamed:@"badge_trophy"]; UIImageView *trophyImageView = [[UIImageView alloc] initWithImage:trophy]; trophyImageView.frame = CGRectMake(152.5, 5, 25, 25); [view addSubview:trophyImageView]; UIImage *medal = [UIImage imageNamed:@"badge_medal"]; UIImageView *medalImageView = [[UIImageView alloc] initWithImage:medal]; medalImageView.frame = CGRectMake(182.5, 5, 25, 25); [view addSubview:medalImageView]; UIImage *heart = [UIImage imageNamed:@"badge_heart"]; UIImageView *heartImageView = [[UIImageView alloc] initWithImage:heart]; heartImageView.frame = CGRectMake(212.5, 5, 25, 25); [view addSubview:heartImageView]; UIImage *coathanger = [UIImage imageNamed:@"badge_coathanger"]; UIImageView *coathangerImageView = [[UIImageView alloc] initWithImage:coathanger]; coathangerImageView.frame = CGRectMake(242.5, 5, 25, 25); [view addSubview:coathangerImageView]; [self.view addSubview:scrollView]; }
Вы используете постоянные позиции для рамок изображения. Вы должны рассчитывать его на основе ширины всего вида. –