用CATextLayer來實現一個UILabel
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顯示</pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!