5

自動サイズ変更に関する多くの情報を見つけましたが、私の問題を解決できたものはありません。次のように、loadView メソッドでビューを呼び出す ViewController (RAViewController) があります。

- (void)loadView
{
    // Set Navigation Bar Title
    self.navigationItem.title = @"RA";

    // Add Background view
    self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Add RAView
    RAView *rAView = [[RAView alloc] initWithFrame:self.view.frame Controller:self];
    [self.view rAView];
}

それが呼び出すビュー (RAView) は次のようになります。

- (id)initWithFrame:(CGRect)frame Controller:(RAViewController *)Controller
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.autoresizesSubviews = YES;
        self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        self.backgroundColor = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];

        controller = Controller;

        // Draw Architecture View
        [self drawArchitectureView];
    }
return self;
}

-(void)drawArchitectureView {
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, self.frame.size.width - 20, 50);

    [button setBackgroundColor:[UIColor grayColor]];
    [button setTitle:@"Overview" forState:UIControlStateNormal];

    [self addSubview:button];
}

何らかの理由で、デバイスが横向きの場合、自動サイズ変更マスクを使用してボタンの幅をサイズ変更できません。どんな助けでも大歓迎です。

4

1 に答える 1

3

同じ高さを維持したいが、完全に中央に配置し、左右から10.0にしたい場合は、次のことを試してください。

-(void)drawArchitectureView {
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, self.frame.size.width - 20, 50);

    button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;

    [button setBackgroundColor:[UIColor grayColor]];
    [button setTitle:@"Overview" forState:UIControlStateNormal];

    [self addSubview:button];
}
于 2011-12-05T17:02:01.453 に答える