以编程方式将UISegmentedControl添加到UIScrollView

时间:2013-02-06 12:25:25

标签: xcode uiscrollview uisegmentedcontrol

我想以编程方式将UISegmentedControl添加到UIScrolview。 我正在使用下面的代码..

我不知道为什么没有启用scrollview。

UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 435)];
    scroll.contentSize = CGSizeMake(320, 700);
    scroll.showsHorizontalScrollIndicator = YES;

    NSArray *menu = [NSArray arrayWithObjects:[UIImage imageNamed:@"Accountimg.png"],[UIImage imageNamed:@"Challengesimg.png"],[UIImage imageNamed:@"Profileimg.png"],[UIImage imageNamed:@"Challengesimg.png"],nil];
    UISegmentedControl *menuSegmentedControl = [[UISegmentedControl alloc] initWithItems:menu];
    menuSegmentedControl.frame = CGRectMake(0,0,450,40);
    menuSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

    [scroll addSubview:menuSegmentedControl];
     [menuScrollView addSubview:scroll];
    [menuSegmentedControl release];
    [scroll release];

我无法横向滚动..

提前致谢

更新:

我可以获得水平滚动。

代码已更新:

 menuSegmentedControl.frame = CGRectMake(0,0,500,35);
    menuSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

     menuScrollView.contentSize = CGSizeMake(menuSegmentedControl.frame.size.width, menuSegmentedControl.frame.size.height);
    menuScrollView.showsVerticalScrollIndicator = NO;

    [menuScrollView addSubview:menuSegmentedControl];
    menuScrollView.clipsToBounds = YES;

谢谢。

0 个答案:

没有答案