YYLabel作者相关地址
首先附上yykit的地址
https://github.com/ibireme/YYKit
作者的博客
http://blog.ibireme.com/2015/11/12/smooth_user_interfaces_for_ios/
YYLabel的使用
YYLabel *label = [[YYLabel alloc] initWithFrame:CGRectMake(100 , 110, 100, 100)];
label.text = @"smallTwo";
label.backgroundColor = [UIColor redColor];
// yylabel 的垂直属性 (区别于系统的多个垂直的功能)
YYLabel的垂直属性
label.textVerticalAlignment = YYTextVerticalAlignmentCenter;
/**
Text vertical alignment.
*/
typedef NS_ENUM(NSInteger, YYTextVerticalAlignment) {
YYTextVerticalAlignmentTop = 0, ///< Top alignment.
YYTextVerticalAlignmentCenter = 1, ///< Center alignment.
YYTextVerticalAlignmentBottom = 2, ///< Bottom alignment.
};
YYLabel的富文本属性
iOS 字符属性NSAttributedString描述
系统自带菊花
/**
* 菊花
*/
- (void)activityIndicatorView {
UIActivityIndicatorView *a = [[UIActivityIndicatorView alloc] init];
a.size = CGSizeMake(80, 80);
a.backgroundColor = [UIColor blackColor];
a.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, [UIScreen mainScreen].bounds.size.height/2);
// 设置圆角
a.layer.cornerRadius = 8;
a.clipsToBounds = YES;
a.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[a startAnimating];
// 设置菊花的颜色
a.color = [UIColor redColor];
[self.view addSubview:a];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[a stopAnimating];
});
}
YYFPSLabel的使用 (检测手机的fps)
主要利用了cadisplaylink, 以下是YYFPSLabel 的代码
.h
//// YYFPSLabel.h// YYKitExample//// Created by ibireme on 15/9/3.// Copyright (c) 2015 ibireme. All rights reserved.//#import/**
Show Screen FPS...
The maximum fps in OSX/iOS Simulator is 60.00.
The maximum fps on iPhone is 59.97.
The maxmium fps on iPad is 60.0.
*/
@interface YYFPSLabel : UILabel
@end
.m
//
// YYFPSLabel.m
// YYKitExample
//
// Created by ibireme on 15/9/3.
// Copyright (c) 2015 ibireme. All rights reserved.
//
#import "YYFPSLabel.h"
#import "YYKit.h"
#define kSize CGSizeMake(55, 20)
@implementation YYFPSLabel {
CADisplayLink *_link;
NSUInteger _count;
NSTimeInterval _lastTime;
UIFont *_font;
UIFont *_subFont;
NSTimeInterval _llll;
}
- (instancetype)initWithFrame:(CGRect)frame {
if (frame.size.width == 0 && frame.size.height == 0) {
frame.size = kSize;
}
self = [super initWithFrame:frame];
self.layer.cornerRadius = 5;
self.clipsToBounds = YES;
self.textAlignment = NSTextAlignmentCenter;
self.userInteractionEnabled = NO;
self.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.700];
_font = [UIFont fontWithName:@"Menlo" size:14];
if (_font) {
_subFont = [UIFont fontWithName:@"Menlo" size:4];
} else {
_font = [UIFont fontWithName:@"Courier" size:14];
_subFont = [UIFont fontWithName:@"Courier" size:4];
}
_link = [CADisplayLink displayLinkWithTarget:[YYWeakProxy proxyWithTarget:self] selector:@selector(tick:)];
[_link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
return self;
}
- (void)dealloc {
[_link invalidate];
}
- (CGSize)sizeThatFits:(CGSize)size {
return kSize;
}
- (void)tick:(CADisplayLink *)link {
if (_lastTime == 0) {
_lastTime = link.timestamp;
return;
}
_count++;
NSTimeInterval delta = link.timestamp - _lastTime;
if (delta < 1) return;
_lastTime = link.timestamp;
float fps = _count / delta;
_count = 0;
CGFloat progress = fps / 60.0;
UIColor *color = [UIColor colorWithHue:0.27 * (progress - 0.2) saturation:1 brightness:0.9 alpha:1];
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d FPS",(int)round(fps)]];
[text setColor:color range:NSMakeRange(0, text.length - 3)];
[text setColor:[UIColor whiteColor] range:NSMakeRange(text.length - 3, 3)];
text.font = _font;
[text setFont:_subFont range:NSMakeRange(text.length - 4, 1)];
self.attributedText = text;
}
@end
简单的使用
/**
* fps label
*/
- (void)FPSlabel {
YYFPSLabel *label = [[YYFPSLabel alloc] init];
[label sizeToFit];
label.left = 10;
label.bottom = SCREEN_HEIGHT - 10;
[self.view addSubview:label];
}