您好,我正在使用HMSegmentedControl进行滑动标签功能。我的代码是这样的。

// Tying up the segmented control to a scroll view
self.segmentedControl4 = [[HMSegmentedControl alloc] initWithFrame:CGRectMake(0, 260, viewWidth, 50)];
self.segmentedControl4.sectionTitles = @[@"Worldwide", @"Local", @"Headlines",@"Four",@"Five"];
self.segmentedControl4.selectedSegmentIndex = 1;
self.segmentedControl4.backgroundColor = [UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1];
self.segmentedControl4.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
self.segmentedControl4.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1]};
self.segmentedControl4.selectionIndicatorColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1];
self.segmentedControl4.selectionStyle = HMSegmentedControlSelectionStyleBox;
self.segmentedControl4.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationUp;
self.segmentedControl4.tag = 3;

__weak typeof(self) weakSelf = self;
[self.segmentedControl4 setIndexChangeBlock:^(NSInteger index) {
    [weakSelf.scrollView scrollRectToVisible:CGRectMake(viewWidth * index, 0, viewWidth, 200) animated:YES];
}];

[self.view addSubview:self.segmentedControl4];

self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 310, viewWidth, 210)];
self.scrollView.backgroundColor = [UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1];
self.scrollView.pagingEnabled = YES;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.contentSize = CGSizeMake(viewWidth * 5, 200);
self.scrollView.delegate = self;
[self.scrollView scrollRectToVisible:CGRectMake(viewWidth, 0, viewWidth, 200) animated:NO];
[self.view addSubview:self.scrollView];

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, viewWidth, 210)];
[self setApperanceForLabel:label1];
label1.text = @"Worldwide";
[self.scrollView addSubview:label1];

UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(viewWidth, 0, viewWidth, 210)];
[self setApperanceForLabel:label2];
label2.text = @"Local";
[self.scrollView addSubview:label2];

UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(viewWidth * 2, 0, viewWidth, 210)];
[self setApperanceForLabel:label3];
label3.text = @"Headlines";
[self.scrollView addSubview:label3];

UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(viewWidth * 2, 0, viewWidth, 210)];
[self setApperanceForLabel:label4];
label4.text = @"Four";
[self.scrollView addSubview:label4];

UILabel *label5 = [[UILabel alloc] initWithFrame:CGRectMake(viewWidth * 2, 0, viewWidth, 210)];
[self setApperanceForLabel:label5];
label5.text = @"Five";
[self.scrollView addSubview:label5];


我的问题是它不显示这些label4和label 5仅显示最多3个。但是所有5个标题都显示在section titles数组中。我该如何解决这些问题。
请帮我。
谢谢This is the github project I used

最佳答案

我不知道HMSegmentedControl,但是我将Page Menu用于段控制器之类的滚动页面。您可以将视图控制器直接添加到此菜单段中。

我不确定这是否是此问题的完美答案,但也可能对其他人有帮助。

关于ios - 如何增加HMSegmentedControl计数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32731551/

10-09 01:47