我想将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];
我已设置自动调整遮罩以采用灵活的左上边距。但它没有用。我错过了什么?请帮忙。
答案 0 :(得分:3)
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];
尝试改为。
答案 1 :(得分:0)
尝试plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin
答案 2 :(得分:0)
我已经将所有这些掩盖用于以下
plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
检查它对我有用吗。