[英]how to draw a text on a circle in SWIFT
I have no clue how to start , so I also do not have any code.我不知道如何开始,所以我也没有任何代码。 My research so far pointed out, that there is no standard functionality and this has to be coded by our self ?
到目前为止,我的研究指出,没有标准功能,这必须由我们自己编写?
any hint or confirmation ?任何提示或确认?
Update using CoreTextArcView, which was suggested by Ashish.使用 Ashish 建议的 CoreTextArcView 进行更新。
Thanks for helping.谢谢你的帮助。 The sample Project which was suggested works for me.
建议的示例项目对我有用。 I can see the blue circle with text on it.
我可以看到上面有文字的蓝色圆圈。 But with integrating this into my project, I have problems.
但是将它集成到我的项目中时,我遇到了问题。 I did the following
我做了以下
I added the Files "CoreTextArcView.h"
and "CoreTextArcView.m"
into my Project.我将文件
"CoreTextArcView.h"
和"CoreTextArcView.m"
到我的项目中。 I can see them in the explorer to the left.我可以在左侧的资源管理器中看到它们。
In my BridgingHeader.h I added to import : #import "CoreTextArcView.h"
在我的 BridgingHeader.h 中,我添加了 import :
#import "CoreTextArcView.h"
I added the Codesample :我添加了 Codesample :
var arctext : CoreTextArcView = CoreTextArcView(frame: CGRectMake(50, 50, 200, 200), font: UIFont.systemFontOfSize(15), text: "Hello this is radious arc with text", radius: 85, arcSize: 130.0, color: UIColor.redColor()) arctext.backgroundColor = UIColor.clearColor() self.view.addSubview(arctext) var arctext : CoreTextArcView = CoreTextArcView(frame: CGRectMake(50, 50, 200, 200), font: UIFont.systemFontOfSize(15), text: "Hello this is radious arc with text", radius: 85, arcSize: 130.0, color : UIColor.redColor()) arctext.backgroundColor = UIColor.clearColor() self.view.addSubview(arctext)
-> I get compile errors in CoreTextArcView.m
: -> 我在
CoreTextArcView.m
得到编译错误:
/Users/user/Desktop/Prototypes/CoreTextArcView.m
/Users/user/Desktop/Prototypes/CoreTextArcView.m:99:14: 'release' is unavailable: not available in automatic reference counting mode
/Users/user/Desktop/Prototypes/CoreTextArcView.m:99:14: ARC forbids explicit message send of 'release'
/Users/user/Desktop/Prototypes/CoreTextArcView.m:100:21: 'retain' is unavailable: not available in automatic reference counting mode
/Users/user/Desktop/Prototypes/CoreTextArcView.m:100:21: ARC forbids explicit message send of 'retain'
/Users/user/Desktop/Prototypes/CoreTextArcView.m:144:33: Cast of Objective-C pointer type 'NSAttributedString *' to C pointer type 'CFAttributedStringRef' (aka 'const struct __CFAttributedString *') requires a bridged cast
/Users/user/Desktop/Prototypes/CoreTextArcView.m:190:63: Cast of C pointer type 'CTFontRef' (aka 'const struct __CTFont *') to Objective-C pointer type 'UIFont *' requires a bridged cast
/Users/user/Desktop/Prototypes/CoreTextArcView.m:298:37: Cast of C pointer type 'CTFontRef' (aka 'const struct __CTFont *') to Objective-C pointer type 'id' requires a bridged cast
/Users/user/Desktop/Prototypes/CoreTextArcView.m:307:24: 'autorelease' is unavailable: not available in automatic reference counting mode
/Users/user/Desktop/Prototypes/CoreTextArcView.m:307:24: ARC forbids explicit message send of 'autorelease'
any help ?有什么帮助吗?
By using this library : https://github.com/javenisme/CurvaView通过使用这个库: https : //github.com/javenisme/CurvaView
var arctext : CoreTextArcView = CoreTextArcView(frame: CGRectMake(50, 50, 200, 200), font: UIFont.systemFontOfSize(15), text: "Hello this is radious arc with text", radius: 85, arcSize: 130.0, color: UIColor.redColor())
arctext.backgroundColor = UIColor.clearColor()
self.view.addSubview(arctext)
Remove arc for one file like as follows (set -fno-objc-arc
to that library's .m file from build phases of your project target) :删除一个文件的弧,如下所示(从项目目标的构建阶段将
-fno-objc-arc
设置为该库的 .m 文件):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.