iOS App订单 星星评价的控件
2017-05-16 18:09
381 查看
//评价星星控件用法
StarView
*startView =
[[StarView
alloc]initWithFrame:CGRectMake(0,
0,
200,
200)];
startView.startNum
=
4;
startView.defalutImage
=
[UIImage
imageNamed:@" "];
startView.selectedImage
=
[UIImage
imageNamed:@" "];
[self.view
addSubview:startView];
星星控件:
#import
"StarView.h"
//星星的大小
#define
startBtnSize 30
//星星的间隙
#define
startInterval 5
@implementation
StarView
-
(instancetype)initWithFrame:(CGRect)frame
{
if
(self
==
[super
initWithFrame:frame])
{
[self
setBackgroundColor:[UIColor
whiteColor]];
}
return
self;
}
-
(void)drawRect:(CGRect)rect
{
self.tag
=
11;
CGFloat
originX =
(rect.size.width-_startNum*startBtnSize-(_startNum-1)*startInterval)
* 0.5;
CGFloat
originY =
(rect.size.height-startBtnSize)*0.5;
for
(int
i
= 0
; i
<</span> _startNum;
i++) {
UIButton
*startButton =
[[UIButton
alloc]initWithFrame:CGRectMake(originX
+ (startInterval+startBtnSize)
* i, originY, startBtnSize,
startBtnSize)];
startButton.tag
= i
;
[startButton setImage:_defalutImage
forState:UIControlStateNormal];
[startButton setImage:_selectedImage
forState:UIControlStateSelected];
[startButton addTarget:self
action:@selector(startBtnClick:)
forControlEvents:UIControlEventTouchUpInside];
[self
addSubview:startButton];
}
//点击手势
UIPanGestureRecognizer
*pan
= [[UIPanGestureRecognizer
alloc]initWithTarget:self
action:@selector(pan:)];
[self
addGestureRecognizer:pan];
}
-
(void)startBtnClick:(UIButton
*)sender
{
for
(int
i
= 0;
i <</span> _startNum;
i++) {
if
(i <=
sender.tag)
{
if
(sender.tag
==
0)
{
UIButton
*button =
[self
viewWithTag:i];
button.selected
=
!button.selected;
if
(button.selected
==
YES)
{
self.score
=
1;
} else
{
self.score
=
0;
}
} else
{
UIButton
*button =
[self
viewWithTag:i];
button.selected
=
YES;
self.score
=
sender.tag;
}
}
else
{
UIButton
*button =
[self
viewWithTag:i];
button.selected
=
NO;
}
}
}
-
(void)pan:(UIPanGestureRecognizer
*)gesture
{
CGPoint
point =
[gesture locationInView:self];
if
(point.x
>
0
&&
point.x
<</span>
_startNum*startBtnSize+(_startNum
-
1)*startInterval)
{
CGFloat
k =
point.x/(startBtnSize+startInterval);
for
(int
i
= 0;
i <</span> _startNum;
i++) {
if
(k >=
i && k < i+1)
{
k = i;
}
}
UIButton
*button =
[self
viewWithTag:k];
[self
startBtnClick:button];
}
}
@end
评价星星控件下载地址:https://pan.baidu.com/s/1jIJsnDc(不好的地方,勿喷)
StarView
*startView =
[[StarView
alloc]initWithFrame:CGRectMake(0,
0,
200,
200)];
startView.startNum
=
4;
startView.defalutImage
=
[UIImage
imageNamed:@" "];
startView.selectedImage
=
[UIImage
imageNamed:@" "];
[self.view
addSubview:startView];
星星控件:
#import
"StarView.h"
//星星的大小
#define
startBtnSize 30
//星星的间隙
#define
startInterval 5
@implementation
StarView
-
(instancetype)initWithFrame:(CGRect)frame
{
if
(self
==
[super
initWithFrame:frame])
{
[self
setBackgroundColor:[UIColor
whiteColor]];
}
return
self;
}
-
(void)drawRect:(CGRect)rect
{
self.tag
=
11;
CGFloat
originX =
(rect.size.width-_startNum*startBtnSize-(_startNum-1)*startInterval)
* 0.5;
CGFloat
originY =
(rect.size.height-startBtnSize)*0.5;
for
(int
i
= 0
; i
<</span> _startNum;
i++) {
UIButton
*startButton =
[[UIButton
alloc]initWithFrame:CGRectMake(originX
+ (startInterval+startBtnSize)
* i, originY, startBtnSize,
startBtnSize)];
startButton.tag
= i
;
[startButton setImage:_defalutImage
forState:UIControlStateNormal];
[startButton setImage:_selectedImage
forState:UIControlStateSelected];
[startButton addTarget:self
action:@selector(startBtnClick:)
forControlEvents:UIControlEventTouchUpInside];
[self
addSubview:startButton];
}
//点击手势
UIPanGestureRecognizer
*pan
= [[UIPanGestureRecognizer
alloc]initWithTarget:self
action:@selector(pan:)];
[self
addGestureRecognizer:pan];
}
-
(void)startBtnClick:(UIButton
*)sender
{
for
(int
i
= 0;
i <</span> _startNum;
i++) {
if
(i <=
sender.tag)
{
if
(sender.tag
==
0)
{
UIButton
*button =
[self
viewWithTag:i];
button.selected
=
!button.selected;
if
(button.selected
==
YES)
{
self.score
=
1;
} else
{
self.score
=
0;
}
} else
{
UIButton
*button =
[self
viewWithTag:i];
button.selected
=
YES;
self.score
=
sender.tag;
}
}
else
{
UIButton
*button =
[self
viewWithTag:i];
button.selected
=
NO;
}
}
}
-
(void)pan:(UIPanGestureRecognizer
*)gesture
{
CGPoint
point =
[gesture locationInView:self];
if
(point.x
>
0
&&
point.x
<</span>
_startNum*startBtnSize+(_startNum
-
1)*startInterval)
{
CGFloat
k =
point.x/(startBtnSize+startInterval);
for
(int
i
= 0;
i <</span> _startNum;
i++) {
if
(k >=
i && k < i+1)
{
k = i;
}
}
UIButton
*button =
[self
viewWithTag:k];
[self
startBtnClick:button];
}
}
@end
评价星星控件下载地址:https://pan.baidu.com/s/1jIJsnDc(不好的地方,勿喷)
相关文章推荐
- 实现iOS应用内付费(In-App&nbsp;P…
- iOS 2.3.7 Your app name to be displayed on the 
- ios app 发布遇到的问题…
- ios点击链接直接跳转到 App&n…
- 如何将IOS&nbsp;App程序发布到苹果…
- IOS APP 真机测试步骤
- 发布iOS应用(xcode5)到App St…
- ios开发--app&nbsp;同时支持iphon…
- iOS APP设计规范大全
- 关于iOS app添加开机启动画面…
- iOS 将图片保存到App中,并取…
- iOS App进入后台获取更…
- iOS网页专用,打开iSecret&nbsp;App
- iOS APP设计规范大全
- TestFlight——完美的iOS&nbsp;App测…
- iOS&nbsp;App&nbsp;名字国际化的办法
- 如何将IOS App程序发布到苹果… 分类: Android开发 2014-05-30 10:56 76人阅读 评论(0) 收藏
- [2015-03-08]IOS&nbsp;App&nbsp;Ic…
- 一步步教你上架IOS APP(转)
- Android App应用之提交到各大… 分类: Android开发 2014-05-30 10:54 221人阅读 评论(0) 收藏