ios开发笔记-8

ios开发笔记-8

评价、显示半颗星

使用的库:TPFloatRatingView

只要设置一下参数就好了:

1
2
3
4
5
6
7
8
9
10
11
12
self.starView = [[TPFloatRatingView alloc] init];
self.starView.frame = CGRectMake(kLeft30, 50, 100, 15);
self.starView.frame = CGRectMake(0, 0, starsWidth, starsHeight);
self.starView.emptySelectedImage = [UIImage imageNamed:@"star_grey"];
self.starView.fullSelectedImage = [UIImage imageNamed:@"star_light"];
self.starView.rating = self.starNum;
self.starView.maxRating = 5;
self.starView.minRating = 0;
self.starView.editable = NO;
self.starView.halfRatings = YES;
self.starView.floatRatings = YES;
[self.starview addSubview:self.starView];

如果需要编辑星星的话,就要使用TPFloatRatingViewDelegate:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
- (void)floatRatingView:(TPFloatRatingView *)ratingView ratingDidChange:(CGFloat)rating
{
self.starnumber = rating;
}
- (void)floatRatingView:(TPFloatRatingView *)ratingView continuousRating:(CGFloat)rating
{
self.starnumber = rating*2;
if (rating==0) {
self.titleLabel.text = @"打个分吧~";
}else if (rating==1){
self.titleLabel.text = @"很差!";
}else if (rating==2){
self.titleLabel.text = @"较差!";
}else if (rating==3){
self.titleLabel.text = @"一般!";
}else if (rating==4){
self.titleLabel.text = @"挺好!";
}else{
self.titleLabel.text = @"很棒!";
}
}

点击显示大图+长按保存

1
2
3
#import <JTSImageInfo.h>
#import <JTSImageViewController.h>
#import <JTSSimpleImageDownloader.h>

设立点击图片的响应:

1
2
3
4
5
6
7
8
9
10
11
12
13
// Create image info
JTSImageInfo *imageInfo = [[JTSImageInfo alloc] init];
imageInfo.image = image;
imageInfo.referenceRect = self.view.window.frame;
imageInfo.referenceView = self.view.window.superview;
// Setup view controller
JTSImageViewController *imageViewer = [[JTSImageViewController alloc]
initWithImageInfo:imageInfo
mode:JTSImageViewControllerMode_Image
backgroundStyle:JTSImageViewControllerBackgroundOption_Blurred];
// Present the view controller.
imageViewer.interactionsDelegate = self;
[imageViewer showFromViewController:self transition:JTSImageViewControllerTransition_FromOffscreen];

使用JTSImageViewControllerInteractionsDelegate:

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
- (BOOL)imageViewerAllowCopyToPasteboard:(JTSImageViewController *)imageViewer {
return YES;
}
- (BOOL)imageViewerShouldTemporarilyIgnoreTouches:(JTSImageViewController *)imageViewer {
return NO;
}
- (void)imageViewerDidLongPress:(JTSImageViewController *)imageViewer atRect:(CGRect)rect {
_selectedImage = imageViewer.image;
ZZActionSheet *actionSheet =
[[ZZActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"保存到手机"
otherButtonTitles:nil];
actionSheet.tag = kImageActionSheetTag;
[actionSheet showInView:imageViewer.view];
}
#pragma mark SavePhotoToPhone
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo
{
if (error) {
[SVProgressHUD showErrorWithStatus:@"保存失败"];
}else {
[SVProgressHUD showSuccessWithStatus:@"保存成功"];
}
}