- Add image named "pattern" to assets.
- Enable slicing, to make the pattern/image repeatable.
- Click the image
- Select 2x
- Click 'Show Slicing'
- Select option with cross icon
- Drag all lines to 4 corners.
Last active
February 5, 2020 10:22
-
-
Save SachinR90/c1e6023088d5138c454ed5695bdacbe4 to your computer and use it in GitHub Desktop.
iOS - Text with Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var imageView: UIImageView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let pattern = UIImage(named: "pattern") | |
imageView.image = pattern | |
// Create the CATextLayer instance. | |
let textLayer = CATextLayer() | |
textLayer.frame = imageView.bounds | |
textLayer.rasterizationScale = UIScreen.main.scale | |
textLayer.contentsScale = UIScreen.main.scale | |
textLayer.fontSize = 60 | |
textLayer.string = "Sachin\nRao"; | |
textLayer.alignmentMode = .center | |
imageView.layer.mask = textLayer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment