0

I've seen almost every question about similar issues, and tried the given answers, but they are not working for me. The thing is: I have a home view, and I have a button, on click, it adds a new button and a label over it, and so on until you "fill" the area, and I want it to be resizable and scrollable, so you can see all the buttons and you can zoom-in to see just some buttons. I don't know if I'm explaining myself clearly...

So, I tried adding everything to a UIView, and it didn't work, I tried adding everything to a UIScrollView, and again it didn't work. I don't know what else to do. I've been dealing with this almost all week without any success. I have to say I am not very experienced on this, I just started to code for iOS about 4 months ago, so please be patient. I would really appreciate any help or guidance you can share.

Here's what I am doing:

- (IBAction) doneAdding:(id) sender{
        boxes = boxes+1;
        UIButton *newBox = [UIButton buttonWithType:UIButtonTypeCustom];
        UIImage *boxImage = [UIImage imageNamed:@"bluecube.jpg"];

    if (boxes <= 4) {
    switch (boxes) {
        case 1:
            newBox.frame = CGRectMake(519, 356, 162, 163);
            break;
        case 2:
            newBox.frame = CGRectMake(681, 519, 162, 163);
            break;
        case 3:
            newBox.frame = CGRectMake(357, 519, 162, 163);
            break;
        case 4:
            newBox.frame = CGRectMake(519, 844, 162, 163);
            break;
            default:
            break;
    }

    [newBox setBackgroundImage:boxImage forState:UIControlStateNormal];
    [newBox addTarget:self action:@selector(goToProject:) forControlEvents:UIControlEventTouchUpInside];
    [homeView addSubview:newBox];


            //I get the text of the label from a textfield 
    UILabel *nameLabel= [ [UILabel alloc ] initWithFrame:CGRectMake(480.0,500.0, 150.0, 43.0) ];
    [[NSUserDefaults standardUserDefaults] setObject: newName.text forKey: @"SomeRandomText"];
    nameLabel.textAlignment =  UITextAlignmentCenter;
    nameLabel.textColor = [UIColor blackColor];
    nameLabel.backgroundColor = [UIColor clearColor];
    nameLabel.font = [UIFont fontWithName:@"Helvetica" size:(12.0)];
    nameLabel.text = [NSString stringWithFormat:@"%@", newName.text];
    [homeView addSubview:nameLabel];
    [newName release];


     }else {
        NSLog(@"No more boxes allowed");
     }
}

1 Answer 1

1

What do you mean with "it doesn't work"? Did you try setting the UIScrollView's contentSize property to a size large enough to contain all the subview's frames?

5
  • yes I did, but it just won't scroll. I checked all the checkboxes that have to be checked on the IB, but no luck.
    – Melisa D
    Aug 19, 2011 at 18:30
  • I don't see any [homeView setContentSize:] there.
    – MrMage
    Aug 19, 2011 at 22:15
  • I didn't set it programmatically, I stated that inside the IB... is there any difference?
    – Melisa D
    Aug 22, 2011 at 14:16
  • You have to adjust it every time you add a new button, and it of course has to be larger than the bounds size of the scroll view...
    – MrMage
    Aug 22, 2011 at 15:08
  • oh... silly me. So there HAS to be a scroll view? or could it just be the view?
    – Melisa D
    Aug 22, 2011 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.