在UIActionSheet上添加UIView作为subView [英] Add UIView as subView on UIActionSheet
问题描述
我正在开展项目,我希望用三个按钮显示UIActionsheet更改,取消和完成,在标题的位置我想放置有一些标签的UIView。我创建了动态UIView并将其添加到actionsheet但是它隐藏在按钮后面我尝试了所有可能的方法来设置setFrame,但是我无法找到解决方案。我想把这个UIView放在UIActionsheet的顶部,然后是按钮。如果您有任何疑问,请随时发表评论。
I am working on project where I want to show UIActionsheet with three buttons Change,Cancel and Done and at the place of title I want to put UIView which has some labels. I have created dynamic UIView and I added it to actionsheet but its hiding behind buttons I tried it by all possible ways to setFrame,bounds but I am not able to find solution. I want to place this UIView at the top of UIActionsheet followed by buttons. If you have any doubts feel free to post comments.
这是我的代码:
-(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];
}
推荐答案
您可以使用此方法,它会将所有按钮向下移动100个像素,请注意这种类型的修改可能会导致您的申请被拒绝
You can use this method, it will move all the buttons down by 100 pixels, please note that this type of modificaiton may result in your application rejection
-(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];
}
这篇关于在UIActionSheet上添加UIView作为subView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!