1、使用HMSegmentedControl实现分段控件
HMSegmentedControl 是 UISegmentedControl 的替代品,模仿了 Google Currents 使用的效果。
A drop-in replacement for UISegmentedControl mimicking the style of the segmented control used in Google Currents and various other Google products.
The easiest way of installing HMSegmentedControl is via CocoaPods.
pod 'HMSegmentedControl', '~> 1.1.0'
If you haven't heard about CocoaPods (seriously, where were you?!), it's a dependency manager for Xcode projects that provides very simple installation of libraries. Here's how to get started.
Install CocoaPods if not already available:
$ [sudo] gem install cocoapods
$ pod setup
Change to the directory of your Xcode project, and Create and Edit your Podfile and add HMSegmentedControl:
$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
platform :ios, '5.0'
pod 'HMSegmentedControl', '~> 1.2.0'
Install into your project:
$ pod install
Open your project in Xcode from the .xcworkspace file (not the usual project file)
$ open MyProject.xcworkspace
HMSegmentedControl.h
and HMSegmentedControl.m
to your project.QuartzCore.framework
to your linked frameworks.#import "HMSegmentedControl.h"
where you want to add the control.The code below will create a segmented control with the default looks:
重要例子2:
// // ViewController.m // 分段控件三方库 // //点击每个不同的segument,转到那个按钮相应的view #import "ViewController.h" #import "HMSegmentedControl.h" CGFloat segmengHight = 35; #define YBSCREEN [UIScreen mainScreen].bounds.size @interface ViewController ()<UIScrollViewDelegate> @property (nonatomic,strong) UIScrollView *scrollView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. CGRect r = [ UIScreen mainScreen ].bounds; HMSegmentedControl *segmented = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"已收公告",@"已发公告",@"要发公告"]]; segmented.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; segmented.frame = CGRectMake(0, 66, self.view.frame.size.width, 35); segmented.backgroundColor = [UIColor yellowColor]; segmented.selectionIndicatorHeight = 3.0f; segmented.selectionIndicatorColor = [UIColor whiteColor]; segmented.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe; segmented.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown; __weak typeof(self) weakSelf = self; self.scrollView.backgroundColor = [UIColor redColor]; //当点击segment,就是点击其他的按钮时,就会通过下方的block,在不同的按钮里实现不同的方法 [segmented setIndexChangeBlock:^(NSInteger index) { //这个方法是scrollView在点击segment按钮后所显示的页面 [weakSelf.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width * index, 0, self.view.frame.size.width, 200) animated:YES]; }]; [self.view addSubview:segmented]; self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 66 + segmengHight, YBSCREEN.width, r.size.height - 66 - segmengHight)]; 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(YBSCREEN.width*3, 640 - 66 - segmengHight); self.scrollView.delegate = self; [self.scrollView scrollRectToVisible:CGRectMake(0, 0, YBSCREEN.width, _scrollView.frame.size.height) animated:NO];//这句可加可不加 [self.view addSubview:self.scrollView]; for (int i= 0; i<3; i++) { UIView *view = [[UIView alloc]initWithFrame:CGRectMake(i*YBSCREEN.width, 0, YBSCREEN.width, r.size.height - 66 - segmengHight)]; if (i == 1) { view.backgroundColor = [UIColor redColor]; }else if (i == 2) { view.backgroundColor = [UIColor yellowColor]; }else { view.backgroundColor = [UIColor blueColor]; } [self.scrollView addSubview:view]; } } @end正在跳转界面(过程截屏):
2、SSZipArchive使用详解
下载SSZipArchive,点击我。或者自己在这里下载。
SSZipArchive功能:
使用前:
2、
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(
NSIndexPath
*)indexPath {
static
NSString
*cellIdentifier = @
"Cell"
;
SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if
(cell ==
nil
) {
NSMutableArray
*leftUtilityButtons = [
NSMutableArray
new
];
NSMutableArray
*rightUtilityButtons = [
NSMutableArray
new
];
[leftUtilityButtons addUtilityButtonWithColor:[UIColor colorWithRed:0.07 green:0.75f blue:0.16f alpha:1.0] icon:[UIImage imageNamed:@
"check.png"
]];
[leftUtilityButtons addUtilityButtonWithColor:[UIColor colorWithRed:1.0f green:1.0f blue:0.35f alpha:1.0] icon:[UIImage imageNamed:@
"clock.png"
]];
[leftUtilityButtons addUtilityButtonWithColor:[UIColor colorWithRed:1.0f green:0.231f blue:0.188f alpha:1.0] icon:[UIImage imageNamed:@
"cross.png"
]];
[leftUtilityButtons addUtilityButtonWithColor:[UIColor colorWithRed:0.55f green:0.27f blue:0.07f alpha:1.0] icon:[UIImage imageNamed:@
"list.png"
]];
[rightUtilityButtons addUtilityButtonWithColor:[UIColor colorWithRed:0.78f green:0.78f blue:0.8f alpha:1.0] title:@
"More"
];
[rightUtilityButtons addUtilityButtonWithColor:[UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f] title:@
"Delete"
];
cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier height:_tableView.rowHeight leftUtilityButtons:leftUtilityButtons rightUtilityButtons:rightUtilityButtons];
cell.delegate =
self
;
}
NSDate
*dateObject = _testArray[indexPath.row];
cell.textLabel.text = [dateObject description];
cell.detailTextLabel.text = @
"Some detail text"
;
return
cell;
}
|
1
2
|
- (
void
)swippableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(
NSInteger
)index;
- (
void
)swippableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(
NSInteger
)index;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#pragma mark - SWTableViewDelegate
- (
void
)swippableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(
NSInteger
)index {
switch
(index) {
case
0:
NSLog
(@
"check button was pressed"
);
break
;
case
1:
NSLog
(@
"clock button was pressed"
);
break
;
case
2:
NSLog
(@
"cross button was pressed"
);
break
;
case
3:
NSLog
(@
"list button was pressed"
);
default
:
break
;
}
}
- (
void
)swippableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(
NSInteger
)index {
switch
(index) {
case
0:
NSLog
(@
"More button was pressed"
);
break
;
case
1:
{
// Delete button was pressed
NSIndexPath
*cellIndexPath = [
self
.tableView indexPathForCell:cell];
[_testArray removeObjectAtIndex:cellIndexPath.row];
[
self
.tableView deleteRowsAtIndexPaths:@[cellIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
break
;
}
default
:
break
;
}
}
|
我贼程序中用到的是通过自己的cell继承与SWTableViewCell,实现左滑。