autoresizingMask 和固定边距的问题
我试图让它与 ViewController 视图中的代码一起使用:
但我无法将其实现工作。
我已经尝试过
-(void)loadView {
UIView *contentView = [[[UIView alloc] init] autorelease];
self.view = contentView;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(5,5,0,100);
button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[contentView addSubview:button];
}
,但按钮的宽度仍然是超级视图的宽度......
我确信有一个简单的解释。
谢谢大家!
安东尼奥
I'm trying to get this to work with code in a ViewController's view:
but I can't get it to work.
I've tried
-(void)loadView {
UIView *contentView = [[[UIView alloc] init] autorelease];
self.view = contentView;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(5,5,0,100);
button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[contentView addSubview:button];
}
but the width of the button is still the width of the superview...
I'm sure there's an easy explanation.
Thanks, everybody!
Antonio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
-initWithFrame:
是 UIView 的指定初始化器。在 Mac 端(NSView),我知道使用-init
而不是-initWithFrame:
时可能会发生奇怪的事情。也许这就是问题所在?-initWithFrame:
is the designated initializer for UIView. On the Mac side (NSView) I know strange things can happen when using-init
instead of-initWithFrame:
. Perhaps this is the problem?我不用担心
autoresizingMask
标志,而是在自定义UIView
子类中重写layoutSubviews
:其中
ContentView
定义为:Instead of bothering with the
autoresizingMask
flag, I overridelayoutSubviews
in customUIView
subclass:where
ContentView
is defined as:试试这个代码。
Try this code.