Mac OS自制进度条
来源:互联网 发布:淘宝衣服模特同一个人 编辑:程序博客网 时间:2024/05/01 07:02
系统进度条:使用setDoubleValue:传送进度值
@property (strong)IBOutletNSProgressIndicator*myprogress;
- (void)updateProgress:(double)value{
static doubleupdateprogress =0;
updateprogress=get_wcnt_vlaue();
[_myprogresssetDoubleValue:updateprogress];
}
自制进度条
总体思路:先新建一个NSView,在这个NSView上画进度条,当然,这个NSView的位置坐标及宽度、高度可以设置为与进度条一样的值。
设置背景框和进度更新框的位置坐标及宽度、高度; 然后设置背景颜色和进度条更新颜色,本例分别为白色和黑色;当进度值更新时,
使用CGRectMake去画更新的进度
注意点:
ios中可以直接在view中设置背景色,可以直接bgimg.backgroundColor,而mac中的背景色是在layer层中,即bgimg.layer.backgroundColor,
且要先将layer层加载layer层,否则就是画的东西已经画上了,但是显示不出来:
bgimg.wantsLayer = YES;//一定要加这一句,加载layer,否则画的东西显示不出来//
// ViewController.m
//
//
#import "ViewController.h"
#import "CustomProgress.h"
@interface ViewController ()
{
CustomProgress *custompro;
NSTimer *timer;
int progress;
}
@property (nonatomic,weak)CALayer *myLayer;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
//self.view.layer.backgroundColor = [NSColor greenColor].CGColor;
//设置NSView的坐标及宽度、高度。mac OS的左下角位置为原点(0,0)
custompro = [[CustomProgressalloc]initWithFrame:CGRectMake(36,284,self.view.frame.size.width-72,50)];
custompro.maxValue =100;//设置进度条最大值
//设置背景色(R/G/B)
//custompro.bgimg.layer.backgroundColor =[NSColor colorWithRed:188/255.0 green:188/255.0 blue:188/255.0 alpha:1].CGColor;
custompro.bgimg.layer.backgroundColor =[NSColor whiteColor].CGColor;//设置背景颜色为白色
custompro.leftimg.layer.backgroundColor =[NSColor blackColor].CGColor;//设置进度条更新颜色为黑色
[self.viewaddSubview:custompro];
//NSLog(@"%@", custompro.leftimg.layer.backgroundColor);
timer =[NSTimerscheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(timer)
userInfo:nil
repeats:YES];
}
-(void)timer
{
progress++;
if (progress<=100) {
[customprosetPresent:progress];//传递进度条进度值
}else
{
[timer invalidate];//移除定时器
timer = nil;
progress = 0;
}
}
//
// CustomProgress.h
//
//
#import <Cocoa/Cocoa.h>
@interface CustomProgress : NSView
@property(nonatomic,retain)NSImageView *bgimg;
@property(nonatomic,retain)NSImageView *leftimg;
//@property(nonatomic, retain)Label *presentlab;
@property(nonatomic)float maxValue;
-(void)setPresent:(int)present;
@end
//
// CustomProgress.m
// test
//
// Created by Develop on 2017/11/6.
// Copyright © 2017年 Develop. All rights reserved.
//
#import "CustomProgress.h"
@implementation CustomProgress
@synthesize bgimg,leftimg;
- (id)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
self.layer.backgroundColor= [NSColorclearColor].CGColor;
bgimg = [[NSImageViewalloc]initWithFrame:CGRectMake(0,0,self.frame.size.width,self.frame.size.height)];
bgimg.wantsLayer =YES;//一定要加这一句,加载layer,否则画的东西显示不出来
bgimg.layer.borderColor = [NSColorclearColor].CGColor;//设置边界颜色
bgimg.layer.borderWidth = 1;
bgimg.layer.cornerRadius =5;//设置边角弧度
[bgimg.layersetMasksToBounds:YES];
[self addSubview:bgimg];
leftimg = [[NSImageViewalloc]initWithFrame:CGRectMake(0,0,0,self.frame.size.height)];
leftimg.wantsLayer =YES;
leftimg.layer.borderColor = [NSColorclearColor].CGColor;
leftimg.layer.borderWidth = 1;
leftimg.layer.cornerRadius =5;
[leftimg.layersetMasksToBounds:YES];
[self addSubview:leftimg];
[selfsetNeedsDisplay:YES];
}
return self;
}
-(void)setPresent:(int)present
{
leftimg.frame =CGRectMake(0,0,self.frame.size.width/self.maxValue*present,self.frame.size.height);
}
@end
效果图:
- Mac OS自制进度条
- Pb自制进度条
- MFC自制进度条
- arm 自制OS
- 自制操作系统OS-1
- 自制进度条的设置方法
- 自制css3进度条小动画
- 自制os(1)-bootloader
- 自制OS 第7步
- Mac OS
- mac os
- Mac OS
- mac os
- mac os
- MAC OS
- Mac OS
- MAC OS
- Android中自制各种进度条的实现
- 关于虚函数、纯虚函数、抽象类、类指针、野指针的一些说明例程
- DRP-filter基础
- log4j的使用详细解析
- 【ElasticSearch】4.ElasticSearch结构化查询
- 基于GPU的并行遗传算法
- Mac OS自制进度条
- 二叉树
- js知识2
- java异常
- tensorflow 计数器 tf.bincount() tf.count_nonzero() tf.unique_with_counts()
- Junit单元测试
- 轻量级分布式 RPC 框架
- CentOS 6.7 安装Docker
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?