开发者

UIscrollView Positioning

开发者 https://www.devze.com 2023-02-08 09:50 出处:网络
I\'m having a few issues with UIscroll views. I\'ve looked at the Reference entry for it but I cant seem to find out how to fix them. Basically I\'m trying to insert a UIlabel into a Scroll view with

I'm having a few issues with UIscroll views. I've looked at the Reference entry for it but I cant seem to find out how to fix them. Basically I'm trying to insert a UIlabel into a Scroll view with the size 320 x 270 (Really the size is arbitrary at the moment). My problem is that I can't seem to get the UILabel to appear in the top left corner of the view.

    detailView.frame = frameDFull; // frameDFull = 320 x 500

    myView.frame = CGRectMake(0, 150, 320, 270); //myFrame is the scroll view

    myView.contentMode = UIViewContentModeScaleAspectFit;
    myView.contentSize = CGSizeMake(320, 2开发者_Go百科70);

    [self.view addSubview:myView];

    //UIView *viewHolder = [[UIView alloc]init];


    UILabel *eventDesc = [[UILabel alloc] init];


    eventDesc.bounds = CGRectMake(0, 0, 320, 100);
    //eventDesc.backgroundColor = [UIColor clearColor];
    eventDesc.text = @"Appears off the screen partially";

    [myView addSubview: eventDesc];


    [eventDesc release];

I can tell that I may have forgotten to do something here. but i'm not sure what. I tried to use a content align seeing as how its essentially a UIview but nothing happened.


Try replacing

UILabel *eventDesc = [[UILabel alloc] init];

with

UILabel *eventDesc = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];

and deleting the line where you set the bounds. You should use the initWithFrame initializer for any UIView (and its subclasses), since the frame determines the view's location within its superview, while the bounds determines the view's location within itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号