У меня есть два UIView
s, скажем containerView
и testView
. Скажем, что ширина testView
больше, чем у containerView
. В таком случае, когда я добавляю testView
как подпункт containerView
, возникает моя проблема. Кадры testView
выходят за рамки containerView
. Вот мой код -Изменить размер UIView
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(60, 154, 200, 200)];
containerView.backgroundColor = [UIColor grayColor];
containerView.clipsToBounds = NO;
UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 260, 100)];
testView.backgroundColor = [UIColor yellowColor];
testView.layer.borderWidth = 3;
testView.layer.borderColor = [[UIColor blackColor] CGColor];
testView.center = CGPointMake(containerView.frame.size.width/2, containerView.frame.size.height/2);
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 25, 230, 50)];
label.text = @"This is a Label to test the size";
[testView addSubview:label];
[containerView addSubview:testView];
[self.view addSubview:containerView];
}
Выход на этот код -
Когда containerView.clipsToBounds = YES;
, выход -
Но что я точно нужно - (Отредактированное изображение)
Когда я добавляю testView
, ширина/высота которого больше его супервизора containerView
, рамка testView
(включая детей) должна быть отрегулирована так, чтобы она идеально вписывалась в ее супервизор.
Я приветствую ваши идеи ..!
вы устанавливаете каждый раз руководство пользователя размером testView? откуда они? –
Я просто запускаю тот же код, который вы указали, и я дал никаких проблем, я имею в виду, что результат - это то, что вам нужно. – BalaChandra
@Bala: Я запускаю Xcode 5.0, iOS7. Это касается версии? – iOS