Конвертировать UIViews, сделанные программно, в UIScrollViews - PullRequest
1 голос
/ 19 марта 2010

Итак, у меня есть куча UIViews, которую я сделал программно и поместил в нее кучу контента (UIButtons, UILabels, UINavigationBars и т. Д.), И большинству этих представлений потребуется на самом деле будет UIScrollViews вместо.

Теперь имейте в виду, я сделал все это с помощью кода, а не Interface Builder. Сначала я попытался заменить каждое объявление UIView на UIScrollView, и это скомпилировалось и работало нормально, однако их нельзя было прокручивать. Это действительно странно.

Вот код, который я изменяю на UIScrollViews, хотя он не прокручивается:

- (void)loadView {

     //allocate the view
     self.view = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
     //self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

     //set the view's background color
     self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"MainBG.jpg"]];

     [self.view addSubview:[SiteOneController myNavBar1:@"Sites"]];

     NSMutableArray *sites = [[NSMutableArray alloc] init];

     NSString *one = @"Constution Center";
     NSString *two = @"Franklin Court";
     NSString *three = @"Presidents House";

     [sites addObject: one];
     [one release];

     [sites addObject: two];
     [two release];

     [sites addObject: three];
     [three release];

     NSString *element;
     int j = 0;
     for (element in sites)
     {
         UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
         UIFont *myBoldFont = [UIFont boldSystemFontOfSize:20.0];
         UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, b + (j*45), c, d)];
         [label setBackgroundColor:[UIColor clearColor]];

         label.text = element;
         label.font = myBoldFont;

         UIImage *img = [UIImage imageNamed:@"ButtonBase.png"];
         [button setImage:img forState:UIControlStateNormal];

         //setframe (where on screen)
         //separation is 15px past the width (45-30)
         button.frame = CGRectMake(a, b + (j*45), c, d);

         // [button setTitle:element forState:UIControlStateNormal];

         button.backgroundColor = [SiteOneController myColor1];

        [button addTarget:self action:@selector(showCCView:)
        forControlEvents:UIControlEventTouchUpInside];
         [button setTag:j];

         [self.view addSubview: button];
         [self.view addSubview:label];
         j++;

     }

 }

Что я делаю не так?

1 Ответ

2 голосов
/ 19 марта 2010

Попробуйте установить размер содержимого для UIScrollView.

т. scrollView.contentSize = CGSizeMake(320,760);

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...