gpt4 book ai didi

objective-c - 自动调整掩码如何工作?

转载 作者:可可西里 更新时间:2023-11-01 04:44:44 26 4
gpt4 key购买 nike

我找到了很多关于自动调整大小的信息,但没有一个能够解决我的问题。我有一个 ViewController (RAViewController),它在其 loadView 方法中调用一个 View ,如下所示:

- (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];
}

它调用的 View (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];
}

出于某种原因,当设备处于横向状态时,我无法获得自动调整大小蒙版来调整按钮宽度。非常感谢任何帮助。

最佳答案

如果你想让它保持相同的高度,但只是保持完全居中,从左边到右边 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];
}

关于objective-c - 自动调整掩码如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8388508/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com