以编程方式设置一些Interface Builder选项

时间:2012-11-21 18:36:57

标签: objective-c ios xcode

大约有一百个原因,我只需要以编程方式创建这个UIViewController子类视图。只有一个,每个其他视图使用IB来制作它的布局。

现在我已经着手完成了使应用程序自动旋转的任务。这在大多数情况下都很好,但我需要帮助理解一些特定于自动调整和对齐的布局选项

如何在此处设置此项(此对象称为“标题”,因此[header setAutoresizingMask:...]

enter image description here

以及这一个

enter image description here

那些是_mapView

我一直在不断抨击可用的选项,但要么没有任何明显的区别,要么我没有设置正确的选项......

    header = [UIButton buttonWithType:UIButtonTypeCustom];
    [header setFrame:CGRectMake(0, 0, self.view.frame.size.width, 170)];

    // this one shoves the header button when in landscape mode to out of view :\
    [header setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
    // the header remains left aligned when in landscape mode...
    [header setContentVerticalAlignment:UIControlContentHorizontalAlignmentCenter];


    [header setBackgroundImage:[[UIImage imageNamed:@"header.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
    [header setBackgroundImage:[[UIImage imageNamed:@"header.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateHighlighted];

    [header addTarget:self action:@selector(goHome) forControlEvents:UIControlEventTouchUpInside];



    _mapView = [[[SPMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)] autorelease];
    [_mapView setDelegate:self];




    [self.view addSubview:_mapView];
    [self.view addSubview:header];

1 个答案:

答案 0 :(得分:2)

第一个:

CGRect newFrame = mainView.frame;
        newFrame.origin = CGPointMake(160, 170);
        newFrame.size = CGSizeMake(768, 170);
        myView.frame = newFrame;
        myView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;

和第二个:

CGRect newFrame = mainView.frame;
            newFrame.origin = CGPointMake(160, 416);
            newFrame.size = CGSizeMake(320, 247);
            myView.frame = newFrame;
            myView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;