最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS自定義水平滾動條、進(jìn)度條

 更新時間:2019年04月28日 10:35:26   作者:hero_wqb  
這篇文章主要為大家詳細(xì)介紹了iOS自定義水平滾動條、進(jìn)度條,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

iOS自定義水平滾動條、進(jìn)度條,繼承UIView,可點(diǎn)擊軌道、滑動滑塊交互。

先看一下效果圖:

簡單說一下邏輯,新建一個繼承UIView的類,分別給軌道、滑塊添加UITapGestureRecognizer點(diǎn)擊、UIPanGestureRecognizer滑動手勢。獲取偏移量,計(jì)算控件位置,刷新視圖。

下面貼上核心代碼:

顯示視圖,在控制器調(diào)用代碼:

HWSlider *slider = [[HWSlider alloc] initWithFrame:CGRectMake(10, 50, 300, 75)];
[self.view addSubview:slider];

HWSlider:

#import <UIKit/UIKit.h>
 
@interface HWSlider : UIView
 
@property (nonatomic, assign) NSInteger score;
 
@end
 
/*** ---------------分割線--------------- ***/
 
#import "HWSlider.h"
#import "UIView+Additions.h"
 
@interface HWSlider ()
 
@property (nonatomic, weak) UIImageView *bubbleImage;
@property (nonatomic, weak) UIImageView *arrowImage;
@property (nonatomic, weak) UILabel *scoreLabel;
@property (nonatomic, weak) UILabel *levelLable;
@property (nonatomic, weak) UIView *trackView;
@property (nonatomic, weak) UIImageView *thumb;
 
@end
 
@implementation HWSlider
 
- (instancetype)initWithFrame:(CGRect)frame
{
 if (self = [super initWithFrame:frame]) {
  _score = 10;
  self.backgroundColor = [UIColor whiteColor];
  
  //氣泡圖片
  UIImageView *bubbleImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.bounds.size.width - 70, 0, 74, 35)];
  [bubbleImage setImage:[UIImage imageNamed:@"alert_teacherEva_bubbleImage"]];
  [self addSubview:bubbleImage];
  _bubbleImage = bubbleImage;
  
  //分?jǐn)?shù)標(biāo)簽
  UILabel *scoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.bounds.size.width - 71.5, 0, 74, 28)];
  scoreLabel.text = @"10";
  scoreLabel.textColor = [UIColor blackColor];
  scoreLabel.font = [UIFont systemFontOfSize:15.f];
  scoreLabel.textAlignment = NSTextAlignmentCenter;
  [self addSubview:scoreLabel];
  _scoreLabel = scoreLabel;
  
  //氣泡箭頭
  UIImageView *arrowImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.bounds.size.width - 16.5, 26, 13, 13)];
  [arrowImage setImage:[UIImage imageNamed:@"alert_teacherEva_arrowImage"]];
  [self addSubview:arrowImage];
  _arrowImage = arrowImage;
  
  //軌道可點(diǎn)擊視圖(軌道只設(shè)置了5pt,通過這個視圖增加以下點(diǎn)擊區(qū)域)
  UIView *tapView = [[UIView alloc] initWithFrame:CGRectMake(0, 34, self.bounds.size.width, 20)];
  [tapView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]];
  [self addSubview:tapView];
  
  //軌道背景
  UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 7.5, self.bounds.size.width, 5)];
  backView.backgroundColor = [UIColor grayColor];
  backView.layer.cornerRadius = 2.5f;
  backView.layer.masksToBounds = YES;
  [tapView addSubview:backView];
  
  //軌道前景
  UIView *trackView = [[UIView alloc] initWithFrame:CGRectMake(1.5, 9, self.bounds.size.width - 3, 2)];
  trackView.backgroundColor = [UIColor greenColor];
  trackView.layer.cornerRadius = 1.f;
  trackView.layer.masksToBounds = YES;
  [tapView addSubview:trackView];
  _trackView = trackView;
  
  //滑塊
  UIImageView *thumb = [[UIImageView alloc] initWithFrame:CGRectMake(self.bounds.size.width - 20, 34, 20, 20)];
  [thumb setImage:[UIImage imageNamed:@"alert_teacherEva_sliderImg"]];
  thumb.userInteractionEnabled = YES;
  thumb.contentMode = UIViewContentModeCenter;
  [thumb addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]];
  [self addSubview:thumb];
  _thumb = thumb;
  
  //級別標(biāo)簽
  UILabel *levelLable = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(thumb.frame) + 7, self.bounds.size.width, 13)];
  levelLable.text = @"非常滿意";
  levelLable.textColor = [UIColor blackColor];
  levelLable.font = [UIFont systemFontOfSize:13.f];
  levelLable.textAlignment = NSTextAlignmentCenter;
  [self addSubview:levelLable];
  _levelLable = levelLable;
 }
 
 return self;
}
 
- (void)setScore:(NSInteger)score
{
 _score = score;
 
 //刷新視圖
 [self reloadViewWithThumbCeneterX:score / 10.0 * self.bounds.size.width];
}
 
//點(diǎn)擊滑動條
- (void)handleTap:(UITapGestureRecognizer *)sender
{
 //刷新視圖
 [self reloadViewWithThumbCeneterX:[sender locationInView:self].x];
}
 
//滑動滑塊
- (void)handlePan:(UIPanGestureRecognizer *)sender
{
 //獲取偏移量
 CGFloat moveX = [sender translationInView:self].x;
 
 //重置偏移量,避免下次獲取到的是原基礎(chǔ)的增量
 [sender setTranslation:CGPointMake(0, 0) inView:self];
 
 //計(jì)算當(dāng)前中心值
 CGFloat centerX = _thumb.centerX + moveX;
 
 //防止瞬間大偏移量滑動影響顯示效果
 if (centerX < 10) centerX = 10;
 if (centerX > self.bounds.size.width - 10) centerX = self.bounds.size.width - 10;
 
 //刷新視圖
 [self reloadViewWithThumbCeneterX:centerX];
}
 
- (void)reloadViewWithThumbCeneterX:(CGFloat)thumbCeneterX
{
 //更新軌道前景色
 _trackView.frameWidth = thumbCeneterX;
 
 //更新滑塊位置
 _thumb.centerX = thumbCeneterX;
 if (_thumb.centerX < 10) {
  _thumb.centerX = 10;
 }else if (_thumb.centerX > self.bounds.size.width - 10) {
  _thumb.centerX = self.bounds.size.width - 10;
 }
 
 //更新箭頭位置
 _arrowImage.centerX = _thumb.centerX;
 
 //更新氣泡標(biāo)簽位置(氣泡圖片寬度74,實(shí)際內(nèi)容寬度66)
 _bubbleImage.centerX = _thumb.centerX;
 if (_bubbleImage.centerX < 33) {
  _bubbleImage.centerX = 33;
 }else if (_bubbleImage.centerX > self.bounds.size.width - 33) {
  _bubbleImage.centerX = self.bounds.size.width - 33;
 }
 
 //更新分?jǐn)?shù)標(biāo)簽位置
 _scoreLabel.centerX = _bubbleImage.centerX;
 
 //分?jǐn)?shù),四舍五入取整
 _score = round(thumbCeneterX / self.bounds.size.width * 10);
 
 //更新標(biāo)簽內(nèi)容
 _scoreLabel.text = [NSString stringWithFormat:@"%ld", _score];
 if (_score <= 3) {
  _levelLable.text = @"極不滿意";
 }else if (_score <= 5) {
  _levelLable.text = @"不滿意";
 }else if (_score <= 7) {
  _levelLable.text = @"一般";
 }else if (_score <= 9) {
  _levelLable.text = @"滿意";
 }else if (_score == 10) {
  _levelLable.text = @"非常滿意";
 }
}
 
@end

Demo 下載鏈接

猜你喜歡:自定義垂直滾動條,可與scrollView聯(lián)動交互。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 解決iOS7上UITextField限制字?jǐn)?shù)輸入導(dǎo)致崩潰問題的方法

    解決iOS7上UITextField限制字?jǐn)?shù)輸入導(dǎo)致崩潰問題的方法

    這篇文章主要為大家分享了解決iOS7上UITextField限制字?jǐn)?shù)輸入導(dǎo)致崩潰問題的方法,感興趣的小伙伴們可以參考一下
    2016-03-03
  • iOS開發(fā)UI篇—xib的簡單使用實(shí)例

    iOS開發(fā)UI篇—xib的簡單使用實(shí)例

    本篇文章主要介紹了iOS開發(fā)UI篇—xib的簡單使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2016-11-11
  • iOS 13適配匯總(推薦)

    iOS 13適配匯總(推薦)

    這篇文章主要介紹了iOS 13適配匯總,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • iOS App開發(fā)中UISearchBar搜索欄組件的基本用法整理

    iOS App開發(fā)中UISearchBar搜索欄組件的基本用法整理

    iOS開發(fā)組件中自帶的UISearchBar提供了很多基礎(chǔ)和好用的搜索欄UI功能,下面就來總結(jié)一下iOS App開發(fā)中UISearchBar搜索欄組件的基本用法整理,需要的朋友可以參考下
    2016-05-05
  • iOS webview捕獲H5按鈕方法示例代碼

    iOS webview捕獲H5按鈕方法示例代碼

    這篇文章主要給大家介紹了關(guān)于iOS webview捕獲H5按鈕方法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • iOS中修改UISearchBar圓角的小技巧分享

    iOS中修改UISearchBar圓角的小技巧分享

    UISearchBar也是iOS開發(fā)常用控件之一,點(diǎn)進(jìn)去看看里面的屬性barStyle、text、placeholder等等。下面這篇文章主要給大家分享了iOS中修改UISearchBar圓角的小技巧,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面來一起看看吧。
    2017-05-05
  • iOS設(shè)置圓角的三種方式

    iOS設(shè)置圓角的三種方式

    本文給大家分享ios設(shè)置圓角的三種方式,相對來說最簡單的一種是第一種方法,具體內(nèi)容詳情參考下本文
    2017-03-03
  • iOS開發(fā)之UITableView左滑刪除等自定義功能

    iOS開發(fā)之UITableView左滑刪除等自定義功能

    今天來給大家介紹下iOS開發(fā)中UITableView左滑實(shí)現(xiàn)微信中置頂,刪除等功能。對大家開發(fā)iOS具有一定的參考借鑒價(jià)值,有需要的朋友們一起來看看吧。
    2016-09-09
  • iOS中NSNumberFormatter的介紹與用法

    iOS中NSNumberFormatter的介紹與用法

    NSNumberFormatter 應(yīng)該可以滿足你對數(shù)據(jù)形式的一般需求,值得了解一下,下面這篇文章主要給大家介紹了關(guān)于iOS中NSNumberFormatter的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2018-09-09
  • IOS UITableView和NavigationBar的常用設(shè)置詳解

    IOS UITableView和NavigationBar的常用設(shè)置詳解

    這篇文章主要介紹了IOS UITableView和NavigationBar的常用設(shè)置詳解的相關(guān)資料,需要的朋友可以參考下
    2017-04-04

最新評論

进贤县| 沙河市| 四川省| 邵阳县| 来凤县| 黔南| 凤山县| 土默特右旗| 五家渠市| 靖西县| 塘沽区| 达拉特旗| 革吉县| 凤阳县| 昌邑市| 张北县| 永吉县| 太和县| 竹溪县| 田东县| 浠水县| 铜鼓县| 丰原市| 肃南| 法库县| 呼和浩特市| 定安县| 云梦县| 通州市| 清水河县| 吴江市| 花莲市| 肇源县| 长治县| 萨嘎县| 三门峡市| 城口县| 桐乡市| 彩票| 江北区| 迭部县|