swift – CATextLayer忽略font-size

swift – CATextLayer忽略font-size,第1张

概述我想为我的图像创建一个文本叠加层.问题是,如果生病了尝试添加第二个文本,如字幕,它会忽略我的字体大小. titleLayer.frame = CGRectMake(0, 80, imageView.bounds.width, 50) subTitleLayer.frame = CGRectMake(0, 130, imageView.bounds.width, 40) title 我想为我的图像创建一个文本叠加层.问题是,如果生病了尝试添加第二个文本,如字幕,它会忽略我的字体大小.
TitleLayer.frame = CGRectMake(0,80,imageVIEw.bounds.wIDth,50)    subTitleLayer.frame = CGRectMake(0,130,40)    TitleLayer.string = "Title"    subTitleLayer.string = "SubTitle"    let Fontname: CFStringRef = "HelveticaNeue"    let FontSubname: CFStringRef = "HelveticaNeue-Thin"    TitleLayer.Font = CTFontCreateWithname(Fontname,16,nil)    subTitleLayer.Font = CTFontCreateWithname(FontSubname,10,nil) // Ignores the Font-size    imageVIEw.layer.addSublayer(TitleLayer)    imageVIEw.layer.addSublayer(subTitleLayer)

新字体是正确的,但它总是与TitleFont一样大小(16).如何@R_25_6502@大小?

看一下关于CATextLayer font property的这个说明

If the Font property is a CTFontRef,a CGFontRef,or an instance
of NSFont,the Font size of the property is ignored.

它清楚地解释了CTFontRef的字体大小被忽略.要解决您的问题,您必须显式设置CATextLayer的FontSize属性

TitleLayer.FontSize = 16subTitleLayer.FontSize = 10
总结

以上是内存溢出为你收集整理的swift – CATextLayer忽略font-size全部内容,希望文章能够帮你解决swift – CATextLayer忽略font-size所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1033177.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存