3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CALayerのサブクラスCATextLayerを使ってみる

Last updated at Posted at 2016-11-04

例によって単純に表示させるだけに1時間かかったので備忘録😩

以下は最低限必要なコードです。

let textLayer = CATextLayer()
textLayer.frame = CGRectMake(0,0, 20, 10)
textLayer.string = "hoge"
textLayer.foregroundColor = UIColor.whiteColor().CGColor
textLayer.fontSize = 10.0
// 次の行は、ないと非Retina状態でレンダリングされる by Takabosoftさん
textLayer.contentsScale = UIScreen.mainScreen().scale
self.view.layer.addSublayer(textLayer)

他のプロパティもあります。以下のリファレンスを参照して下さい。

CATextLayer - QuartzCore | Apple Developer Documentation

文字列を別の要素と連動して動かしたいんです。おとなしくUILabelを使った方がいいのだろうか…


ブログやっています:http://weed.nagoya

3
5
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?