• 进度条控件 (UIProgressView)


    进度条控件 (UIProgressView)

    1. UIProgressView 控件属性

    UIProgressView 属性截图 : 

    (1) Style 属性

    Style 属性 : 

    -- Default : 使用默认风格的进度条;

    -- Bar : 工具条风格;

    (2) progress 属性

    Progress 属性 : 设置已进行的进度的比例值, 取值范围 0.0 ~ 1.0;

    (3) Progress Tint 属性

    Progress Tint 属性 : 已完成的颜色;

    (4) Track Tint 属性

    Track Tint 属性 : 进度条轨道颜色;

    (5) progressImage 属性

    ProgressImage 属性 : 设置进度条完成的图片;

    -- 注意 : 该属性在 Interface Builder 中没有体现出来;

    (6) trackImage 属性

    trackImage 属性 : 设置进度条轨道图片;

    -- 注意 : 代码中设置, 界面设计文件中无该属性;

    2. 可拉伸图片

    (1) 可拉伸图片用法

    可拉伸图片作用 : 在上述进度条中, 设置的 progressImage 和 trackImage 必须是可拉伸图片;

    (2) 可拉伸图片创建

    创建可拉伸图片 : 使用 UIImage 创建 可拉伸图片, 通过 UIEdgeInsets 结构体定义图片拉伸区域;

    -- UIEdgeInsets 结构体 : 包括 left, top, right, bottom 四个值;

    -- 缩放主体 : 图片缩放只在 UIEdgeInsets 定义的 四个属性值 区域缩放, 图片的中心部分是不进行缩放的;

    3. 定制进度条示例

    (1) 相关 API 简介 

    相关 API 简介 : 

    -- 创建可拉伸的 UIImage : 

    [objc] view plaincopy
     
    1. UIImage * trackImage = [[UIImage imageNamed:@"Snip20151210_139.png"] resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];  

    -- 为进度条设置可拉伸图片 : 

    [objc] view plaincopy
     
    1. //将可拉伸图片设置给进度条  
    2. self.progress3.progressImage = progressImage;  
    3. self.progress3.trackImage = trackImage;  



    -- 创建定时器 

    [objc] view plaincopy
     
    1. //定时器  
    2. timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(doProgress) userInfo:nil repeats:YES];  



    (2) 代码示例

    代码示例 : 

    -- 界面设计文件 : 

    -- OCViewController.h : 

    [objc] view plaincopy
     
    1. //  
    2. //  OCViewController.h  
    3. //  UIProgressView  
    4. //  
    5. //  Created by octopus on 15-12-10.  
    6. //  Copyright (c) 2015年 www.octopus.org.cn. All rights reserved.  
    7. //  
    8.   
    9. #import <UIKit/UIKit.h>  
    10.   
    11. @interface OCViewController : UIViewController  
    12.   
    13. @property (strong, nonatomic) IBOutlet UIProgressView *progress1;  
    14. @property (strong, nonatomic) IBOutlet UIProgressView *progress2;  
    15. @property (strong, nonatomic) IBOutlet UIProgressView *progress3;  
    16. - (IBAction)click:(id)sender;  
    17. @end  



    -- OCViewController.m : 

    [objc] view plaincopy
     
    1. //  
    2. //  OCViewController.m  
    3. //  UIProgressView  
    4. //  
    5. //  Created by octopus on 15-12-10.  
    6. //  Copyright (c) 2015年 www.octopus.org.cn. All rights reserved.  
    7. //  
    8.   
    9. #import "OCViewController.h"  
    10.   
    11. @interface OCViewController ()  
    12.   
    13. @end  
    14.   
    15. @implementation OCViewController  
    16.   
    17. //定时器  
    18. NSTimer * timer;  
    19. //进度条进度  
    20. CGFloat progress;  
    21.   
    22. /* 
    23.     CGFloat : 是 float 类型, 在 IOS 中定义了下面的类型  
    24.     -- 32 位 : typedef float CGFloat;// 32-bit 
    25.     -- 64 位 : typedef double CGFloat;// 64-bit 
    26.   
    27.     CGPoint : 二维坐标点; 
    28.     -- 定义代码 :  
    29.         struct CGPoint { 
    30.             CGFloat x; 
    31.             CGFloat y; 
    32.         }; 
    33.         typedef struct CGPoint CGPoint; 
    34.   
    35.     CGSize : 矩形的宽度和高度; 
    36.     -- 定义代码 :  
    37.         struct CGSize { 
    38.             CGFloat width; 
    39.             CGFloat height; 
    40.         }; 
    41.         typedef struct CGSize CGSize; 
    42.   
    43.     CGRect : 矩形的位置和大小; 
    44.     -- 定义代码 :  
    45.         struct CGRect { 
    46.             CGPoint origin; 
    47.             CGSize size; 
    48.         }; 
    49.         typedef struct CGRect CGRect; 
    50.  */  
    51.   
    52. - (void)viewDidLoad  
    53. {  
    54.     [super viewDidLoad];  
    55.     // Do any additional setup after loading the view, typically from a nib.  
    56.       
    57.     //创建 可拉伸的图片, 平铺样式  
    58.     UIImage * trackImage = [[UIImage imageNamed:@"Snip20151210_139.png"] resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];  
    59.     UIImage * progressImage = [[UIImage imageNamed:@"Snip20151210_140.png"] resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];  
    60.       
    61.     //将可拉伸图片设置给进度条  
    62.     self.progress3.progressImage = progressImage;  
    63.     self.progress3.trackImage = trackImage;  
    64.       
    65. }  
    66.   
    67. - (void)didReceiveMemoryWarning  
    68. {  
    69.     [super didReceiveMemoryWarning];  
    70.     // Dispose of any resources that can be recreated.  
    71. }  
    72.   
    73. - (IBAction)click:(id)sender {  
    74.     //进度条  
    75.     progress = 0;  
    76.       
    77.     //定时器  
    78.     timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(doProgress) userInfo:nil repeats:YES];  
    79.       
    80. }  
    81.   
    82. - (void) doProgress{  
    83.     progress += 0.1;  
    84.     if(progress > 1.0){  
    85.         [timer invalidate];  
    86.     }else{  
    87.         [self.progress1 setProgress:progress animated:YES];  
    88.         [self.progress2 setProgress:progress animated:YES];  
    89.         [self.progress3 setProgress:progress animated:YES];  
    90.     }  
    91.       
    92.       
    93. }  
    94.   
    95. @end  



    -- 运行展示 : 可拉伸图片效果没有出现, 待调试;

  • 相关阅读:
    [BZOJ] IOI2015 Boxes纪念品盒
    [BZOJ] 聚会
    [BZOJ] 地精部落
    [BZOJ] 最长距离
    正则
    cookie实例 记住用户名密码
    cookie封装
    碎片整合 例子
    闭包 tab切换 实例
    闭包
  • 原文地址:https://www.cnblogs.com/sungk/p/5108823.html
Copyright © 2020-2023  润新知