我们可以将 UIButton 放在 UIScrollView 中,反之亦然吗? [英] Can we put a UIButton in a UIScrollView and vice versa in iPhone

查看:35
本文介绍了我们可以将 UIButton 放在 UIScrollView 中,反之亦然吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以提供给定场景的代码示例吗?

Can someone provide a code example for the given scenario?

推荐答案

UIScrollView *scrollview = [[[UIScrollView alloc] initWithFrame:CGRectMake(0.0F, 0.0F, 320.0F, 480.0F)] autorelease];
[self.view addSubview:scrollView];

UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[button setTitle:@"Title" forState:UIControlStateNormal];
[button setFrame:CGrectMake(0.0F, 0.0F, 50.0F, 50.0F)];
[scrollView addSubview:button];

如果必须向 UIButton 添加子视图,则只需按相反的顺序添加:

If you have to add a subview to a UIButton then you would just to it in the opposite order:

UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[button setTitle:@"Title" forState:UIControlStateNormal];
[button setFrame:CGrectMake(0.0F, 0.0F, 50.0F, 50.0F)];
[[self.view addSubview:button];
UIScrollView *scrollview = [[[UIScrollView alloc] initWithFrame:CGRectMake(0.0F, 0.0F, 320.0F, 480.0F)] autorelease];
[button addSubview:scrollView];

但是 scrollview 将阻止来自按钮的触摸,除非您将 userInteractionEnabledexclusiveTouch 属性设置为 NO在滚动视图上.但这会破坏我认为在按钮中包含滚动视图的目的.

But the scrollview will block the touches from the button unless you set userInteractionEnabled and exclusiveTouch properties to NO on the scrollview. But that would defeat the purpose of having a scrollview inside a button I think.

这篇关于我们可以将 UIButton 放在 UIScrollView 中,反之亦然吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆