仿网易滑动界面+仿安卓顶部滑动按钮
来源:互联网 发布:阿里云空间代理 编辑:程序博客网 时间:2024/04/29 21:44
本文是基于实现的 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
- 仿网易滑动界面+仿安卓顶部滑动按钮
- 仿网易新闻顶部滑动条效果
- 仿网易、人人滑动界面的实现
- 高仿网易新闻顶部滑动条效果
- 高仿网易新闻顶部滑动条效果
- Android高仿网易新闻顶部滑动条效果
- 高仿网易新闻顶部滑动条效果 (源码)
- 高仿网易新闻顶部滑动条效果
- 仿网易主界面左右滑动以及顶部大图,下拉刷新.上拉加载更多等功能集成控件
- 仿android系统主界面 下方的小按钮滑动
- IOS轻松实现仿网易新闻顶部滑动指示器(Scrollview实现)
- 仿Ios滑动开关按钮
- 仿switch风格滑动按钮
- 仿网易的滑动门技术
- 仿网易/今日头条滑动视图
- 仿网易云音乐的滑动效果
- 仿网易严选标签栏滑动
- 仿网易云音乐滑动效果
- android Audio 详解( 二 )
- hdu 1207 汉诺塔II【规律】
- 二叉树的创建,先序遍历,中序遍历,后序遍历
- mycncart操作使用教程 - 语言设置
- RadioButton + selector实现Tab导航效果
- 仿网易滑动界面+仿安卓顶部滑动按钮
- ios使用常用正则表达式验证手机号
- solr5.4.0-demo
- mycncart操作使用教程 - 商品分类
- 运输层—TCP的连接管理
- 回顾我的2015
- 快速排序
- xcode 修改 production name
- mycnart操作使用教程 -如何默认不显示 商品价格。会员登陆...