用CATextLayer來實現一個(gè)UILabel
發表時間:2020-10-19
發布人:葵宇科技
浏覽次數:36
用CATextLayer來實現一個(gè)UILabel
by 伍雪(xuě)穎
[img]http://img.blog.csdn.net/20150104212858888?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcmFpbmxlc3Zpbw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
CATextLayer *textLayer = [CATextLayerlayer];
textLayer.frame =CGRectMake(100,100,100,100);
[self.view.layeraddSublayer:textLayer];
textLayer.foregroundColor = [UIColorblackColor].CGColor;
textLayer.alignmentMode =kCAAlignmentJustified;
textLayer.wrapped =YES;
UIFont *font = [UIFontsystemFontOfSize:15];
CFStringRef fontName = (__bridgeCFStringRef)font.fontName;
CGFontRef fontRef =CGFontCreateWithFontName(fontName);
textLayer.font = fontRef;
textLayer.fontSize = font.pointSize;
CGFontRelease(fontRef);
NSString *text =@"Cupid laid by his brand, and fell asleep";
textLayer.string = text;
textLayer.contentsScale = [UIScreen mainScreen].scale; // 在Retina顯示