#import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIScrollView *scrollViewForAccordian; @property (weak, nonatomic) IBOutlet UIView* mainView; @end @implementation ViewController @synthesize scrollViewForAccordian; @synthesize mainView; - (void)viewDidLoad { [super viewDidLoad]; /* NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:scrollViewForAccordian attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0]; NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:scrollViewForAccordian attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0]; */ NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:scrollViewForAccordian attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]; NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:scrollViewForAccordian attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]; NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:scrollViewForAccordian attribute:NSLayoutAttributeRight multiplier:1.0 constant:0]; NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:scrollViewForAccordian attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]; scrollViewForAccordian.translatesAutoresizingMaskIntoConstraints = NO; [mainView addConstraints:@[leftConstraint, bottomConstraint, topConstraint, rightConstraint]]; scrollViewForAccordian.backgroundColor = [UIColor redColor]; // [self makeCell]; } - (void)viewWillAppear:(BOOL)animated { [self.mainView addSubview:self.scrollViewForAccordian]; NSLog(@"RIGHTHERE %@", NSStringFromCGRect(self.scrollViewForAccordian.frame)); } - (void)makeCell { //Making the Cell UIView *viewForOutertable = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ([[ UIScreen mainScreen ] bounds].size.width), 44)]; viewForOutertable.translatesAutoresizingMaskIntoConstraints = NO; NSDictionary *viewsDictionary = @{@"Cell":viewForOutertable}; /* NSLayoutConstraint *horizontalConstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[myCell]-0-|" options:0 metrics:nil views:viewsDictionary]; [viewForOutertable addConstraint:horizontalConstraint]; */ //Setting the buttons UIButton *buttonToEnlarge = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, ([[ UIScreen mainScreen ] bounds].size.width) , 44)]; [buttonToEnlarge setImage:[UIImage imageNamed:@"ltgrey.jpg"] forState:UIControlStateNormal]; [buttonToEnlarge setImage:[UIImage imageNamed:@"grey.jpg"] forState:UIControlStateSelected]; [buttonToEnlarge addTarget:self action:@selector(expandButtonTapped:) forControlEvents: UIControlEventTouchUpInside]; [viewForOutertable addSubview:buttonToEnlarge]; scrollViewForAccordian.backgroundColor = [UIColor redColor]; [scrollViewForAccordian addSubview:viewForOutertable]; } -(void)expandButtonTapped:(UIButton *)sender { NSLog(@"Button Clicked"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end