仿网易滑动界面+仿安卓顶部滑动按钮
2015-12-31 19:21
549 查看
本文是基于实现的 HMSegmentedControl,仅仅是对初学者提供一个小小的思路
HMSegmentedControl的链接 https://github.com/HeshamMegid/HMSegmentedControl
{
HMSegmentedControl *_copytopAndroid;//仿安卓顶部按钮栏
HMSegmentedControl *_copyNeteaseSideslip;//仿网易顶部
UIScrollView *_scrollVierw;
}
//仿安卓顶部按钮
//初始化的数组,可以根据需求改变,根据最长的来确定长度
_copytopAndroid = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"热点",@"体育",@"头条",@"娱乐",@"直播",@"汽车",@"轻松一刻",@"时尚"]];
// _copytopAndroid.backgroundColor = [UIColor redColor];
//目测是自动适配啥的,具体不知道
_copytopAndroid.autoresizingMask = UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleWidth;
//设置按钮栏的frame
_copytopAndroid.frame = CGRectMake(20, 64+50, self.view.frame.size.width-20*2, 40);
//设置文字距离左右上下的高度,
_copytopAndroid.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10);
//选择条(底部滑动的那个)的样式
_copytopAndroid.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
//选择条的具体位置(上部或者下部)
_copytopAndroid.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
_copytopAndroid.selectionIndicatorHeight =3;
_copytopAndroid.selectionIndicatorColor = [UIColor redColor];
//是否显示两个按钮之间的线
_copytopAndroid.verticalDividerEnabled = YES;
//设置两个按钮之间线的颜色
_copytopAndroid.verticalDividerColor = [UIColor blackColor];
//两个按钮之间线的粗细
_copytopAndroid.verticalDividerWidth = 1.0f;
//设置按钮的属性
NSDictionary *defaults_nomal = @{
NSFontAttributeName : [UIFont systemFontOfSize:15.0f],
NSForegroundColorAttributeName :[UIColor grayColor],
};
NSMutableDictionary *resultingAttrs_nomal = [NSMutableDictionary dictionaryWithDictionary:defaults_nomal];
_copytopAndroid.titleTextAttributes=resultingAttrs_nomal;
//设置选中之后按钮的属性
NSDictionary *defaults = @{
NSFontAttributeName : [UIFont systemFontOfSize:15.0f],
NSForegroundColorAttributeName :[UIColor redColor],
};
NSMutableDictionary *resultingAttrs = [NSMutableDictionary dictionaryWithDictionary:defaults];
_copytopAndroid.selectedTitleTextAttributes=resultingAttrs;
//添加事件
[_copytopAndroid addTarget:self action:@selector(selectedbtn:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_copytopAndroid];
//仿网易侧滑界面
_copyNeteaseSideslip = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"今日头条",@"开心一刻",@"经济要闻",@"其他"]];
_copyNeteaseSideslip.autoresizingMask = UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleWidth;
_copyNeteaseSideslip.frame = CGRectMake(20, 64+50+100, self.view.frame.size.width-20*2, 40);
_copyNeteaseSideslip.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10);
_copyNeteaseSideslip.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
_copyNeteaseSideslip.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
_copyNeteaseSideslip.selectionIndicatorHeight =3;
_copyNeteaseSideslip.selectionIndicatorColor = [UIColor redColor];
_copyNeteaseSideslip.verticalDividerEnabled = NO;
_copyNeteaseSideslip.verticalDividerColor = [UIColor blackColor];
_copyNeteaseSideslip.verticalDividerWidth = 1.0f;
_copyNeteaseSideslip.titleTextAttributes=resultingAttrs_nomal;
_copyNeteaseSideslip.selectedTitleTextAttributes=resultingAttrs;
_copyNeteaseSideslip.tag = 1;
[_copyNeteaseSideslip addTarget:self action:@selector(selectedbtn:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_copyNeteaseSideslip];
_scrollVierw = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 64+50+100+40, self.view.frame.size.width-20*2, 200)];
_scrollVierw.pagingEnabled = YES;
_scrollVierw.scrollEnabled = YES;
_scrollVierw.delegate =self;
_scrollVierw.showsVerticalScrollIndicator = NO;
_scrollVierw.contentSize = CGSizeMake((self.view.frame.size.width-20*2)*4, 200);
[self.view addSubview:_scrollVierw];
for (int i =0; i<4; i++) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-20*2)*i, 0, (self.view.frame.size.width-20*2), 200)];
view.backgroundColor = [UIColor colorWithRed:(100+20*i)/255.0 green:(150+20*i)/255.0 blue:(200+20*i)/255.0 alpha:1];
[_scrollVierw addSubview:view];
}
下载链接 我写的一个小demo http://download.csdn.net/detail/zhanniuniu/9385968
HMSegmentedControl的链接 https://github.com/HeshamMegid/HMSegmentedControl
{
HMSegmentedControl *_copytopAndroid;//仿安卓顶部按钮栏
HMSegmentedControl *_copyNeteaseSideslip;//仿网易顶部
UIScrollView *_scrollVierw;
}
//仿安卓顶部按钮
//初始化的数组,可以根据需求改变,根据最长的来确定长度
_copytopAndroid = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"热点",@"体育",@"头条",@"娱乐",@"直播",@"汽车",@"轻松一刻",@"时尚"]];
// _copytopAndroid.backgroundColor = [UIColor redColor];
//目测是自动适配啥的,具体不知道
_copytopAndroid.autoresizingMask = UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleWidth;
//设置按钮栏的frame
_copytopAndroid.frame = CGRectMake(20, 64+50, self.view.frame.size.width-20*2, 40);
//设置文字距离左右上下的高度,
_copytopAndroid.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10);
//选择条(底部滑动的那个)的样式
_copytopAndroid.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
//选择条的具体位置(上部或者下部)
_copytopAndroid.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
_copytopAndroid.selectionIndicatorHeight =3;
_copytopAndroid.selectionIndicatorColor = [UIColor redColor];
//是否显示两个按钮之间的线
_copytopAndroid.verticalDividerEnabled = YES;
//设置两个按钮之间线的颜色
_copytopAndroid.verticalDividerColor = [UIColor blackColor];
//两个按钮之间线的粗细
_copytopAndroid.verticalDividerWidth = 1.0f;
//设置按钮的属性
NSDictionary *defaults_nomal = @{
NSFontAttributeName : [UIFont systemFontOfSize:15.0f],
NSForegroundColorAttributeName :[UIColor grayColor],
};
NSMutableDictionary *resultingAttrs_nomal = [NSMutableDictionary dictionaryWithDictionary:defaults_nomal];
_copytopAndroid.titleTextAttributes=resultingAttrs_nomal;
//设置选中之后按钮的属性
NSDictionary *defaults = @{
NSFontAttributeName : [UIFont systemFontOfSize:15.0f],
NSForegroundColorAttributeName :[UIColor redColor],
};
NSMutableDictionary *resultingAttrs = [NSMutableDictionary dictionaryWithDictionary:defaults];
_copytopAndroid.selectedTitleTextAttributes=resultingAttrs;
//添加事件
[_copytopAndroid addTarget:self action:@selector(selectedbtn:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_copytopAndroid];
//仿网易侧滑界面
_copyNeteaseSideslip = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"今日头条",@"开心一刻",@"经济要闻",@"其他"]];
_copyNeteaseSideslip.autoresizingMask = UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleWidth;
_copyNeteaseSideslip.frame = CGRectMake(20, 64+50+100, self.view.frame.size.width-20*2, 40);
_copyNeteaseSideslip.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10);
_copyNeteaseSideslip.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
_copyNeteaseSideslip.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
_copyNeteaseSideslip.selectionIndicatorHeight =3;
_copyNeteaseSideslip.selectionIndicatorColor = [UIColor redColor];
_copyNeteaseSideslip.verticalDividerEnabled = NO;
_copyNeteaseSideslip.verticalDividerColor = [UIColor blackColor];
_copyNeteaseSideslip.verticalDividerWidth = 1.0f;
_copyNeteaseSideslip.titleTextAttributes=resultingAttrs_nomal;
_copyNeteaseSideslip.selectedTitleTextAttributes=resultingAttrs;
_copyNeteaseSideslip.tag = 1;
[_copyNeteaseSideslip addTarget:self action:@selector(selectedbtn:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_copyNeteaseSideslip];
_scrollVierw = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 64+50+100+40, self.view.frame.size.width-20*2, 200)];
_scrollVierw.pagingEnabled = YES;
_scrollVierw.scrollEnabled = YES;
_scrollVierw.delegate =self;
_scrollVierw.showsVerticalScrollIndicator = NO;
_scrollVierw.contentSize = CGSizeMake((self.view.frame.size.width-20*2)*4, 200);
[self.view addSubview:_scrollVierw];
for (int i =0; i<4; i++) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-20*2)*i, 0, (self.view.frame.size.width-20*2), 200)];
view.backgroundColor = [UIColor colorWithRed:(100+20*i)/255.0 green:(150+20*i)/255.0 blue:(200+20*i)/255.0 alpha:1];
[_scrollVierw addSubview:view];
}
下载链接 我写的一个小demo http://download.csdn.net/detail/zhanniuniu/9385968
相关文章推荐
- ios使用常用正则表达式验证手机号
- ssh-keygen 不是内部或外部命令
- mycncart操作使用教程 - 文章管理
- 四柱汉诺塔问题
- 如何减小与“大牛”的差距
- 数据库升级代码学习
- TextView显示html样式的文字
- android Audio 详解( 二 )
- 2015年终总结-公司版
- sc7731 Android 5.1 LCD驱动简明笔记之一
- Linux卷管理详解--PV(物理卷)--VG(卷组)--LV(逻辑卷)--PE(基本单元)
- grub rescue问题解决
- android Audio 详解( 一 )
- 开发中最困难的部分是什么
- 2015年个人总结
- mycncart操作使用教程 - 模组
- java中如何实现下载word功能
- Spark核心编程-分组取topN
- 使用栈实现括号匹配
- 验证码【脑洞大开】【转】