Can someone provide a code example for the given scenario?
+1
A:
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];
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];
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.
texmex5
2010-05-14 10:52:00
Fine!This is the code to set UIButton in UIScrollView. How to do it vice versa?What's the code?
Maxood
2010-05-14 11:04:50
Added the vice versa part.
texmex5
2010-05-14 11:27:14
+1
A:
UIButton in UIScrollView:
UIScrollView *theScrollView = [[[UIScrollView alloc] initWithFrame:CGRectMake(0.0F, 0.0F, 320.0F, 480.0F)] autorelease];
[self.view addSubview: theScrollView];
UIButton *theButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[theButton setTitle:@"Ok" forState:UIControlStateNormal];
[theButton setFrame:CGrectMake(0.0F, 0.0F, 100.0F, 50.0F)];
[theScrollView addSubview:theButton];
and UIScrollView in UIButton:
UIButton *theButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[theButton setTitle:@"Ok" forState:UIControlStateNormal];
[theButton setFrame:CGRectMake(0.0F, 0.0F, 320.0F, 480.0F)];
UIScrollView *theScrollView = [[[UIScrollView alloc] initWithFrame:CGrectMake(0.0F, 0.0F, 100.0F, 50.0F)] autorelease];
[theButton addSubview:theScrollView];
[self.view addSubview: theButton];
luvieere
2010-05-14 11:10:13