当我点击一个按钮时,我正在我的应用程序中调用一个自定义选择器。
选择器看起来像一个气泡,所以我将它指向这样的按钮:
thePicker.presentFromRect = button.frame;
我需要选择器从这个按钮向下显示 300 像素。我怎样才能做到这一点?
如何在上述语句中添加 300 像素高度?
您应该创建一个新框架并编辑其高度属性,如下所示:
CGRect frame = button.frame;
frame.size.height += 30;
thePicker.presentFromRect = frame;
您需要使用:
CGRect frame = self.window.frame;
frame.size.height += 30;
thePicker.presentFromRect = frame;
首先获取按钮的框架,以便能够对其进行处理。然后根据需要更改他的高度,访问size属性。最后,将框架重新分配给选择器
CGRect buttonFrame = button.frame;
buttonFrame.size.height += 300;
thePicker.presentFromRect = buttonFrame;