我正在开展项目,我希望用三个按钮显示UIActionsheet更改,取消和完成,在标题的位置我想放置有一些标签的UIView。我创建了动态UIView,我将它添加到了动作表但是它隐藏在按钮后面我尝试了所有可能的方法来设置setFrame,但是我无法找到解决方案。我想把这个UIView放在UIActionsheet的顶部,然后是按钮。如果您有任何疑问,请随时发表评论。
这是我的代码:
-(IBAction)tapbutton:(id)sender
{
Lablesubview *view = [[Lablesubview alloc]init];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Change"
otherButtonTitles:@"Done",nil];
[actionSheet addSubview:view];
[actionSheet showInView:self.view];
}
答案 0 :(得分:3)
你可以使用这种方法,它会将所有按钮向下移动100个像素,请注意这种类型的修改可能会导致你的应用程序被拒绝
-(IBAction)tapbutton:(id)sender
{
//create the view
Lablesubview *view = [[Lablesubview alloc]init];
//Set the frame
view.frame = CGRectMake(0, 10, 320, 100);
view.backgroundColor = [UIColor greenColor];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Change"
otherButtonTitles:@"Done",nil];
[actionSheet showInView:self.view];
CGRect rect;
//expand the action sheet
rect = actionSheet.frame;
rect.size.height +=100;
rect.origin.y -= 100;
actionSheet.frame = rect;
//Displace all buttons
for (UIView *vButton in actionSheet.subviews) {
rect = vButton.frame;
rect.origin.y += 100;
vButton.frame = rect;
}
//Add the new view
[actionSheet addSubview:view];
}