1

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

我不知道为什么没有启用滚动视图。

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;

谢谢你。

4

0 回答 0