3

我想将 UIButton 固定到 iPhone 屏幕的右下角。3.5英寸和4英寸屏幕。

这是我写的代码。但在 iPhone4 和 iPhone5 中,按钮始终保持在 x=265,y=361 上。

UIImage* plusImage = [UIImage imageNamed:@"Plus.png"];
UIButton* plusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[plusButton setImage:plusImage forState:UIControlStateNormal];
[plusButton setFrame:CGRectMake(265, 361, plusImage.size.width, plusImage.size.height)];
plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self.view addSubview:plusButton];

我已经将自动调整大小的蒙版设置为灵活的顶部和左侧边距。但它没有用。我错过了什么?请帮忙。

4

3 回答 3

4
UIImage* plusImage = [UIImage imageNamed:@"Plus.png"];
UIButton* plusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[plusButton setImage:plusImage forState:UIControlStateNormal];
CGSize viewSize = self.view.frame.size;
[plusButton setFrame:CGRectMake(viewSize.width - plusImageSize.width, viewSize.height - plusImageSize.height, plusImage.size.width, plusImage.size.height)];
plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self.view addSubview:plusButton];

试试那个。

于 2013-01-08T11:03:18.583 回答
0

尝试 plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin

于 2013-01-08T10:48:24.240 回答
0

我已经使用了所有这些掩蔽如下

plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;

检查它是否对我有用。

于 2013-01-08T10:55:51.560 回答