YYKit的使用!?。?/h2>

YYLabel作者相關(guān)地址

首先附上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 的垂直屬性 (區(qū)別于系統(tǒng)的多個(gè)垂直的功能)

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描述

系統(tǒng)自帶菊花


/**

*? 菊花

*/

- (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);

// 設(shè)置圓角

a.layer.cornerRadius = 8;

a.clipsToBounds = YES;

a.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;

[a startAnimating];

// 設(shè)置菊花的顏色

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的使用 (檢測(cè)手機(jī)的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

簡(jiǎn)單的使用

/**

*? fps label ? ??

*/

- (void)FPSlabel {

YYFPSLabel *label = [[YYFPSLabel alloc] init];

[label sizeToFit];

label.left = 10;

label.bottom =? SCREEN_HEIGHT - 10;

[self.view addSubview:label];

}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容