【问题标题】:Uisegment buttons over scroll view滚动视图上的 Uisegment 按钮
【发布时间】:2013-06-06 19:09:21
【问题描述】:

嗨,我试图在 uiscrollview 上放置一个 uisegmented 控件,因为我希望它们水平滚动这是我尝试过的代码

UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 600, 300)];
scroll.contentSize = CGSizeMake(500, 50);
scroll.showsHorizontalScrollIndicator = YES;
scroll.pagingEnabled = YES;
scroll.showsHorizontalScrollIndicator = YES;
scroll.autoresizingMask = YES;
scroll.autoresizesSubviews = YES;
NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two",  @"Three",@"four",@"Five", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(0,10, 500, 50);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 4;

[scroll addSubview:segmentedControl];
[self.view addSubview:scroll];

请任何人帮我完成这个。在此先感谢编码愉快

【问题讨论】:

    标签: uiscrollview uisegmentedcontrol


    【解决方案1】:

    滚动视图的框架必须小于滚动视图的内容大小。如果你会增加你的内容大小肯定会奏效。例如:-

     UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
        scroll.contentSize = CGSizeMake(500, 50);
        scroll.showsHorizontalScrollIndicator = YES;
        scroll.pagingEnabled = YES;
        scroll.showsHorizontalScrollIndicator = YES;
        scroll.autoresizingMask = YES;
        scroll.autoresizesSubviews = YES;
        NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two",  @"Three",@"four",@"Five", nil];
    
    
        UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
        segmentedControl.frame = CGRectMake(0,10, 500, 50);
        segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
        segmentedControl.selectedSegmentIndex = 4;
    
        [scroll addSubview:segmentedControl];
        [self.view addSubview:scroll];
    

    如果支持,请将答案标记为正确。非常感谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-10
      • 2016-05-06
      相关资源
      最近更新 更多