美文网首页iOS 开发 学习
iOS App订单 星星评价的控件

iOS App订单 星星评价的控件

作者: 清蘂翅膀的技术 | 来源:发表于2017-05-16 13:36 被阅读41次

//评价星星控件用法

StarView*startView = [[StarViewalloc]initWithFrame:CGRectMake(0,0,200,200)];

startView.startNum=4;

startView.defalutImage= [UIImageimageNamed:@""];

startView.selectedImage= [UIImageimageNamed:@""];

[self.viewaddSubview:startView];

星星控件:

#import"StarView.h"

//星星的大小

#define startBtnSize 30

//星星的间隙

#define startInterval 5

@implementationStarView

- (instancetype)initWithFrame:(CGRect)frame {

if(self== [superinitWithFrame:frame]) {

[selfsetBackgroundColor:[UIColorwhiteColor]];

}

returnself;

}

- (void)drawRect:(CGRect)rect {

self.tag=11;

CGFloatoriginX = (rect.size.width-_startNum*startBtnSize-(_startNum-1)*startInterval) *0.5;

CGFloatoriginY = (rect.size.height-startBtnSize)*0.5;

for(inti =0; i <_startNum; i++) {

UIButton*startButton = [[UIButtonalloc]initWithFrame:CGRectMake(originX + (startInterval+startBtnSize) * i, originY,startBtnSize,startBtnSize)];

startButton.tag= i ;

[startButtonsetImage:_defalutImageforState:UIControlStateNormal];

[startButtonsetImage:_selectedImageforState:UIControlStateSelected];

[startButtonaddTarget:selfaction:@selector(startBtnClick:)forControlEvents:UIControlEventTouchUpInside];

[selfaddSubview:startButton];

}

//点击手势

UIPanGestureRecognizer*pan = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(pan:)];

[selfaddGestureRecognizer:pan];

}

- (void)startBtnClick:(UIButton*)sender {

for(inti =0; i <_startNum; i++) {

if(i <= sender.tag) {

if(sender.tag==0) {

UIButton*button = [selfviewWithTag:i];

button.selected= !button.selected;

if(button.selected==YES) {

self.score=1;

}else{

self.score=0;

}

}else{

UIButton*button = [selfviewWithTag:i];

button.selected=YES;

self.score= sender.tag;

}

}else{

UIButton*button = [selfviewWithTag:i];

button.selected=NO;

}

}

}

- (void)pan:(UIPanGestureRecognizer*)gesture {

CGPointpoint = [gesture locationInView:self];

if(point.x>0&& point.x<_startNum*startBtnSize+(_startNum-1)*startInterval) {

CGFloatk = point.x/(startBtnSize+startInterval);

for(inti =0; i <_startNum; i++) {

if(k >= i && k < i+1) {

k = i;

}

}

UIButton*button = [selfviewWithTag:k];

[selfstartBtnClick:button];

}

}

@end

评价星星控件下载地址:https://pan.baidu.com/s/1jIJsnDc(不好的地方,勿喷)

相关文章

  • iOS App订单 星星评价的控件

    //评价星星控件用法 StarView*startView = [[StarViewalloc]initWithF...

  • [IOS] 星星评价控件

    抽空写了个星星评价的小控件,把自己想到的功能都加上了,不过现在没有支持动画。 https://github.com...

  • iOS 评价控件

    Demo下载地址

  • iOS开发星级评分

    前言 在开发电商类的app中,我们经常会遇到用户评价“打星”这样的需求,因为iOS上没有这个控件,所以这时需要我们...

  • iOS App内评价

    前言 iOS 10.3 引入了SKStoreReviewController的Api, 用于在App内评价. 评价...

  • UIStackView 的各种使用案例

    之前开发的APP都是适配到 iOS 7 ,iOS 8,对UIStackView这种最低支持 iOS9 的高端控件,...

  • iOS 星星评分控件

    简单的自用星星控件,有空再加上手势 星星的间距取的是星星的宽度的五分之一,view的宽度等于五个星星加上四个空隙 ...

  • GCD之dispatch_group的简单使用

    在商城APP中,有些时候需要先处理图片上传。商品APP中,某个订单的立即评价,存在多个商品,一起评价。先将这多张图...

  • GCD之dispatch_semaphore_t的简单使用

    在商城APP中,有些时候需要先处理图片上传。商品APP中,某个订单的立即评价,存在多个商品,一起评价。先将这多张图...

  • iOS UITableView的简单封装

    UITableView是iOS中最常用的控件之一,几乎所有的APP都不可避免的要用到这个控件。UITableVie...

网友评论

    本文标题:iOS App订单 星星评价的控件

    本文链接:https://www.haomeiwen.com/subject/izrlxxtx.html