ios - 如何增加 HMSegmentedControl 计数?

标签 ios

你好,我正在使用 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];

我的问题是它不显示这些标签 4,标签 5 最多只显示 3 个。但是所有 5 个标题都显示在部分标题数组中。我该如何解决这些问题。 请帮我。 谢谢This is the github project I used

最佳答案

我不知道 HMSegmentedControl 但我使用 Page Menu用于像段 Controller 这样的滚动页面。您可以将 View Controller 直接添加到此菜单段中。

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

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

相关文章:

ios - Apple 开发者帐户作为个人和公司/组织之间的区别

iphone - 在 Xcode 中设置前置摄像头

ios - watchOS2 配对属性

ios - UITextView 后面的 ImageView 未剪切到边界

ios - PubNub 长轮询与套接字 - 移动电池生命周期

ios - UITextView需要一段时间才能将文本加载到其中,如何显示加载图标?

ios - 如何将数据附加到来自 swift 3 中服务器响应的字典中?

ios - SDWebImage 不缓存

ios - 如何确定语言环境货币是否有小数点

objective-c - Objective-C 中的枚举定义形式