仿網易滑動介面+仿安卓頂部滑動按鈕
本文是基於實現的 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