redraw a custom UIVIEW when device orientation changed SWIFT 5 - swift

I wrote the code down for new UIVIEW but after device rotation the draw of UIVIEW do not get cleaned up for new situation! And stay visible for user! look at picture. how we can fix the problem?
import UIKit
class ViewController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
}
override func viewDidLayoutSubviews()
{
var drawView = UIView()
let drawViewOffsetFromTop = max( 25 , Int( view.safeAreaInsets.top ) )
let drawViewOffsetFromBottom = max( 25 , Int( view.safeAreaInsets.bottom ) )
let drawViewWidth = Int( view.frame.size.width ) - 2*25
let drawViewHeight = Int( view.frame.size.height) - drawViewOffsetFromTop - drawViewOffsetFromBottom
drawView = UIView(frame: CGRect(x: 25 , y: drawViewOffsetFromTop, width: drawViewWidth , height: drawViewHeight ))
drawView.backgroundColor = UIColor.gray
drawView.layer.cornerRadius = 15
view.addSubview(drawView)
}
}

You can use Autolayout to make things simple.
Remove override viewDidLayoutSubviews completely.
Use the following in viewDidLoad
override func viewDidLoad()
{
super.viewDidLoad()
var drawView = UIView()
//Setup Constraints for `drawView`
drawView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
drawView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 25),
drawView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -25),
drawView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 15),
drawView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -15)
])
}
Edit: Solution without Autolayout
The issue is that your drawView is added multiple times in the view hierarchy! You can just add it once and only change the frame.
class ViewController: UIViewController {
var drawView = UIView()
override func viewDidLoad()
{
super.viewDidLoad()
view.addSubview(drawView)
drawView.backgroundColor = UIColor.gray
drawView.layer.cornerRadius = 15
}
override func viewDidLayoutSubviews()
{
let drawViewOffsetFromTop = max( 25 , Int( view.safeAreaInsets.top ) )
let drawViewOffsetFromBottom = max( 25 , Int( view.safeAreaInsets.bottom ) )
let drawViewWidth = Int( view.frame.size.width ) - 2*25
let drawViewHeight = Int( view.frame.size.height) - drawViewOffsetFromTop - drawViewOffsetFromBottom
drawView.frame = CGRect(x: 25 , y: drawViewOffsetFromTop, width: drawViewWidth , height: drawViewHeight )
}
}

First of all, you should not put creating UIView code in viewDidLayoutSubviews, create and add it in viewDidLoad instead. You can put view frame update code in viewDidLayoutSubviews.
The problem is you are adding drawView multiple times without removing existing ones. In addition you are initializing drawView multiple times in different lines unnecessarily.
To fix the problem, create drawView in your controller, add it to superview in viewDidLoad and edit your viewDidLayoutSubviews just like below:
class ViewController: UIViewController {
private var drawView : UIView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(drawView)
}
override func viewDidLayoutSubviews() {
let drawViewOffsetFromTop = max(25 , Int(view.safeAreaInsets.top))
let drawViewOffsetFromBottom = max(25 , Int(view.safeAreaInsets.bottom))
let drawViewWidth = Int(view.frame.size.width ) - 2*25
let drawViewHeight = Int(view.frame.size.height) - drawViewOffsetFromTop - drawViewOffsetFromBottom
drawView.frame = CGRect(x: 25, y: drawViewOffsetFromTop, width: drawViewWidth, height: drawViewHeight)
drawView.backgroundColor = UIColor.gray
drawView.layer.cornerRadius = 15
}
}

//▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
var drawView = UIView()
//▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
//█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █
override func viewDidLoad()
{
super.viewDidLoad()
view.backgroundColor = UIColor.gray
}
//█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █
//█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █
override func viewDidLayoutSubviews()
{
//▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
let backView = UIView(frame: CGRect(x: 0 , y: 0, width: view.frame.size.width , height: view.frame.size.height ))
backView.backgroundColor = UIColor.gray
view.addSubview(backView)
//▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
//▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
let drawViewOffsetFromTop = max( 25 , Int( view.safeAreaInsets.top ) )
let drawViewOffsetFromBottom = max( 25 , Int( view.safeAreaInsets.bottom ) )
let drawViewOffsetFromRight = max( 25 , Int( view.safeAreaInsets.right ) )
let drawViewOffsetFromLeft = max( 25 , Int( view.safeAreaInsets.left ) )
//▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
//▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
let drawViewWidth = Int( view.frame.size.width ) - drawViewOffsetFromRight - drawViewOffsetFromLeft
let drawViewHeight = Int( view.frame.size.height) - drawViewOffsetFromTop - drawViewOffsetFromBottom
//▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
//▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
drawView = UIView(frame: CGRect(x: drawViewOffsetFromRight , y: drawViewOffsetFromTop, width: drawViewWidth , height: drawViewHeight ))
//▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
//▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
drawView.backgroundColor = UIColor.systemTeal
drawView.layer.cornerRadius = 12
drawView.layer.borderWidth = 5
drawView.layer.borderColor = UIColor.black.cgColor
view.addSubview(drawView)
//▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
}
//█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █

Related

Swift inheritance carrying over constraints

In my swift code below I am attempting to use inheritance. When I go to class middle the constraints on the initial view controller are still being applied. Even though in middle class I attempt to attach new constraints to right button they are not being applied. You can see what is going wrong in the photo below.
import UIKit
class ViewController: UIViewController {
var right = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
[right].forEach{
$0.translatesAutoresizingMaskIntoConstraints = false
view.addSubview($0)
$0.backgroundColor = UIColor(
red: .random(in: 0.0...1),
green: .random(in: 0.9...1),
blue: .random(in: 0.7...1),
alpha: 1
)
}
NSLayoutConstraint.activate([
right.bottomAnchor.constraint(equalTo: view.bottomAnchor),
right.leadingAnchor.constraint(equalTo: view.leadingAnchor),
right.heightAnchor.constraint(equalTo: view.heightAnchor,multiplier: 0.1),
right.widthAnchor.constraint(equalTo: view.widthAnchor,multiplier: 1),
])
right.setTitle(">", for: .normal)
right.addTarget(self, action: #selector(nexte), for: .touchDown)
}
#objc func nexte(){
let vc = middle()
vc.modalPresentationStyle = .overCurrentContext // actually .fullScreen would be better
self.present(vc, animated: true)
}
}
class middle : ViewController{
var leftbtn = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
[leftbtn].forEach{
$0.translatesAutoresizingMaskIntoConstraints = false
view.addSubview($0)
$0.backgroundColor = UIColor(
red: .random(in: 0.0...1),
green: .random(in: 0.9...1),
blue: .random(in: 0.7...1),
alpha: 1
)
}
NSLayoutConstraint.activate([
leftbtn.bottomAnchor.constraint(equalTo: view.bottomAnchor),
leftbtn.leadingAnchor.constraint(equalTo: view.leadingAnchor),
leftbtn.heightAnchor.constraint(equalTo: view.heightAnchor,multiplier: 0.1),
leftbtn.widthAnchor.constraint(equalTo: view.widthAnchor,multiplier: 0.5 ),
right.bottomAnchor.constraint(equalTo: view.bottomAnchor),
right.leadingAnchor.constraint(equalTo: leftbtn.trailingAnchor),
right.heightAnchor.constraint(equalTo: view.heightAnchor,multiplier: 0.1),
right.widthAnchor.constraint(equalTo: view.widthAnchor,multiplier: 0.5 ),
])
}
}
You are saying super.viewDidLoad() in Middle. super is ViewController so ViewController's viewDidLoad is executed too. Thus "When I go to class middle the constraints on the initial view controller are still being applied".
You should rethink your whole architecture here.

Calculate the size of text for draw in context(Core Graphics)?

I need to know the size of my text that I am going to draw in context. How we can find the size of created text inside context?
What I should put for sizeOfText?
this is my code:
let text = "Some test"
let locationOfText: CGPoint = .zero
let fontOFText: CGFloat = 30
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .left
let attrib: [NSAttributedString.Key: Any] = [
.font: UIFont.boldSystemFont(ofSize: fontOFText),
.paragraphStyle: paragraphStyle]
let sizeOfComponent = labelSimulator(withThisFont: UIFont.boldSystemFont(ofSize: fontOFText), withThisText: text)
let sizeOfText = CGSize(width: sizeOfComponent.width, height: sizeOfComponent.height)
text.draw(in: CGRect(origin: locationOfText, size: sizeOfText), withAttributes: Attrib)
This part is my way to find the Size of text, do you know better way, hit me!
//█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █
func labelSimulator(withThisFont: UIFont, withThisText: String) -> CGSize
{
//▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
let simulator = UILabel()
simulator.font = withThisFont
simulator.text = withThisText
//▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
//▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
return simulator.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude))
//▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
}
//█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █
I have already shown to you how to calculate the height of your text on your last question. You just need to add a margin to it and move on. The width you choose will determine the final height:
let pdfFormat = UIGraphicsPDFRendererFormat()
let metaData: [CFString : Any] = [
kCGPDFContextTitle: "Hello, World!",
kCGPDFContextAuthor: "Omid",
kCGPDFContextCreator: "PDF Creator"]
pdfFormat.documentInfo = metaData as [String: Any]
// your PDF page size
let size: CGSize = .init(width: 8.5 * 72.0, height: 11 * 72.0)
let bounds: CGRect = .init(origin: .zero, size: size)
let pdfRenderer = UIGraphicsPDFRenderer(bounds: bounds, format: pdfFormat)
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let data = pdfRenderer.pdfData { (context) in
context.beginPage()
let text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
let fontOFText: CGFloat = 30
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .left
let attrib: [NSAttributedString.Key: Any] = [
.font: UIFont.boldSystemFont(ofSize: fontOFText),
.paragraphStyle: paragraphStyle]
let margin: CGFloat = 20
let attributedText = NSAttributedString(string: text, attributes: attrib)
let textCanvas = bounds.insetBy(dx: margin, dy: 0).size
let textSize = attributedText.boundingRect(with: textCanvas,
options: [.usesFontLeading, .usesLineFragmentOrigin],
context: nil).size
let rect = CGRect(origin: .init(x: margin/2, y: 0), size: textSize)
text.draw(in: rect, withAttributes: attrib)
let nextTextYPosition = rect.origin.y + rect.size.height
print("nextTextYPosition", nextTextYPosition)
"NEXT TEXT".draw(in: .init(origin: .init(x: margin/2, y: nextTextYPosition), size: CGSize.init(width: 200, height: 200)), withAttributes: attrib)
}
let fileURL = documentDirectory.appendingPathComponent("test.pdf")
try data.write(to: fileURL)
For the specific situation you've described, the size you generally want is CGSize(width: .greatestFiniteMagnitude, height: .greatestFiniteMagnitude). Depending on the context you're drawing into, you may want to constrain the height. If you want it to wrap, then you can constrain the width.
The in: parameter here is a constraining box. It's the largest box allowed. It doesn't have to tightly match the text.
If you need the actual size (in order to put an outline around it for example), you can compute that using .boundingRect(with:options:attributes:context:).
(Noting your edit, you seem to have the right idea. You just don't need a label. You can ask the string directly.)
For example, based on your code, there's no need for labelSimulator:
let sizeOfText = CGSize(width: CGFloat.greatestFiniteMagnitude, height: .greatestFiniteMagnitude)
text.draw(in: CGRect(origin: locationOfText, size: sizeOfText), withAttributes: attrib)

use uipangesture on a nslayout constraint

My swift code below is using nslayout constraints in view did load. I have tried to place a uipangestureRecognizer on a imageview. To get the image view to move around the uiview controller. Right now If I touch the imageview nothing happens. I understand that I have placed permenent constraints in view did load. I just dont know how to get the imageview to move around. The image view I am trying to move is fight[0].
import UIKit
class ViewController: UIViewController {
var pic = UIImageView()
var draw = UIView()
let fight = (0..<10).map { _ in UIImageView() }
var g2 = UIPanGestureRecognizer()
override func viewDidLoad() {
super.viewDidLoad()
fight[0].image = UIImage(named: "a.png")
g2 = UIPanGestureRecognizer(target: self, action: #selector(ViewController.g1Method))
fight[0].addGestureRecognizer(g2)
fight.forEach{
$0.backgroundColor = .clear
view.addSubview($0)
$0.translatesAutoresizingMaskIntoConstraints = false
}
[pic,draw].forEach{
$0.backgroundColor = .red
view.addSubview($0)
$0.translatesAutoresizingMaskIntoConstraints = false
}
// Do any additional setup after loading the view.
NSLayoutConstraint.activate ([
fight[0].trailingAnchor.constraint(equalTo: view.trailingAnchor, constant :0),
fight[0].topAnchor.constraint(equalTo: view.topAnchor, constant : 50),
fight[0].heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.10, constant: 0),
fight[0].widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.10, constant: 0),
fight[0].leadingAnchor.constraint(equalTo: view.leadingAnchor, constant : 0),
])
}
#objc func g1Method(_ sender: UIPanGestureRecognizer){
self.view.bringSubviewToFront(sender.view!)
let tranistioon = sender.translation(in: self.view)
sender.view!.center = CGPoint(x: sender.view!.center.x + tranistioon.x, y: sender.view!.center.y + tranistioon.y)
sender.setTranslation(CGPoint.zero,in: self.view) }
}
By default, UIImageView do not have user interaction enabled.
Add this line inside viewDidLoad():
fight[0].isUserInteractionEnabled = true
You should now be able to drag that image view around.

AdMob implement (only code, no main storyboard)

I want put Ad banner in my app.
I don't have the storyboard, I 've 4 ViewCOntroller, in the main I've this, can someone help me please?
In AppDelegate: GADMobileAds.configure(withApplicationID: "...")
import UIKit
import Firebase
import GoogleMobileAds
class ViewController: UIViewController {
var window: UIWindow?
override func viewDidLoad(){
super.viewDidLoad()
self.title="Andrea Damante Quiz"
self.view.backgroundColor=UIColor(patternImage: UIImage(named: "andrea15.jpeg")!)
let backgroundImage = UIImageView(frame: UIScreen.main.bounds)
backgroundImage.image = UIImage(named: "andrea15.jpeg")
backgroundImage.contentMode = UIViewContentMode.scaleAspectFill
self.view.insertSubview(backgroundImage, at: 0)
setupViews()
}
#objc func btnGetStartedAction() {
let v=QuizVC()
self.navigationController?.pushViewController(v, animated: true)
}
func setupViews() {
self.view.addSubview(lblTitle)
lblTitle.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 150).isActive=true
lblTitle.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive=true
lblTitle.widthAnchor.constraint(equalToConstant: 250).isActive=true
lblTitle.heightAnchor.constraint(equalToConstant: 80).isActive=true
self.view.addSubview(btnGetStarted)
btnGetStarted.heightAnchor.constraint(equalToConstant: 50).isActive=true
btnGetStarted.widthAnchor.constraint(equalToConstant: 150).isActive=true
btnGetStarted.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive=true
btnGetStarted.centerYAnchor.constraint(equalTo: self.view.centerYAnchor, constant: 0).isActive=true
}
let lblTitle: UILabel = {
let lbl=UILabel()
lbl.text="Quiz"
lbl.textColor=UIColor.darkGray
lbl.textAlignment = .center
lbl.font = UIFont.systemFont(ofSize: 46)
lbl.numberOfLines=2
lbl.translatesAutoresizingMaskIntoConstraints=false
return lbl
}()
let btnGetStarted: UIButton = {
let btn=UIButton()
btn.setTitle("Via!", for: .normal)
btn.setTitleColor(UIColor.white, for: .normal)
btn.backgroundColor=UIColor.orange
btn.layer.cornerRadius=5
btn.layer.masksToBounds=true
btn.translatesAutoresizingMaskIntoConstraints=false
btn.addTarget(self, action: #selector(btnGetStartedAction), for: .touchUpInside)
return btn
}()
}
You need to declare and set up a GADBannerView and add it to your view controller. You won't need a UIWindow. Use this code:
import GoogleMobileAds
import UIKit
class ViewController: UIViewController {
var bannerView: GADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
// In this case, we instantiate the banner with desired ad size.
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
addBannerViewToView(bannerView)
}
func addBannerViewToView(_ bannerView: GADBannerView) {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
view.addConstraints(
[NSLayoutConstraint(item: bannerView,
attribute: .bottom,
relatedBy: .equal,
toItem: bottomLayoutGuide,
attribute: .top,
multiplier: 1,
constant: 0),
NSLayoutConstraint(item: bannerView,
attribute: .centerX,
relatedBy: .equal,
toItem: view,
attribute: .centerX,
multiplier: 1,
constant: 0)
])
}
}
which was taken from here: https://developers.google.com/admob/ios/banner.
Also make sure to set the ad unit ID and the delegate:
override func viewDidLoad() {
super.viewDidLoad()
...
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
bannerView.rootViewController = self
bannerView.load(GADRequest())
}
But again, you'll everything you need in the official guide.

whats the seed for spacefiller pattern in conway's game of life

Can anybody tell me what is the seed for spacefiller pattern in Conway's game of life ? I am planning to include some interesting patterns for user in my game.
Thanks much,
From Golly, a really nice Sourceforge Game-of-Life project with a huge number of seeds:
███ ███
█ █ █ █
████ █ █ ████
█ █ █ █ █ █
█ █ █ █ █ █
█ █ ██ █ █ ██ █ █
█ █ ███ ███ █ █
█ █ █ █ █ █
█ █ ███████ █ █
█ █ ██ █ ██ █ █ ██ █ ██ █ █
█ █ ██ ███████████ ██ █ █
█ █ ██ ██ █ █
████ ███████████████████ ████
█ █ █ █
███████████
█ █
█████████
█
███ ███
█ █
███ ███
███ ███
█ ██ ██ █
███ ███
█ █
I believe you are referring to the glider pattern?
One of the frames looks like;
010
001
111
Edit:
Try
http://www.argentum.freeserve.co.uk/lex_s.htm#spacefiller
I believe missKK is looking for a Conway's Game of Life pattern that will, if placed in empty space, fill the space with an agar. Although new Life patterns are discovered all the time, as of today the smallest known pattern is Tim Coe's "Max", a 187-cell pattern which fits in a 27x27 bounding box:
#N Max
#O Tim Coe
#C A spacefiller that fills space with zebra stripes.
#C www.conwaylife.com/wiki/index.php?title=Max
x = 27, y = 27, rule = s23/b3
18bo8b$17b3o7b$12b3o4b2o6b$11bo2b3o2bob2o4b$10bo3bobo2bobo5b$10bo4bobo
bobob2o2b$12bo4bobo3b2o2b$4o5bobo4bo3bob3o2b$o3b2obob3ob2o9b2ob$o5b2o
5bo13b$bo2b2obo2bo2bob2o10b$7bobobobobobo5b4o$bo2b2obo2bo2bo2b2obob2o
3bo$o5b2o3bobobo3b2o5bo$o3b2obob2o2bo2bo2bob2o2bob$4o5bobobobobobo7b$
10b2obo2bo2bob2o2bob$13bo5b2o5bo$b2o9b2ob3obob2o3bo$2b3obo3bo4bobo5b4o
$2b2o3bobo4bo12b$2b2obobobobo4bo10b$5bobo2bobo3bo10b$4b2obo2b3o2bo11b$
6b2o4b3o12b$7b3o17b$8bo!
The Lifewiki website has more information on this pattern and other known spacefillers.