For the record, I'm just gettin' my feet wet with Emacs, Doom, and I've never written a line of Lisp before (I'm assuming this code is Lisp?). This is a good ol' learning moment for me, so feel free to spare me no detail in the response (or just solve my problems, totally fine either way).
I snagged this script from the interweb, it 'almost' works perfect. There's a big ol' indent on the lefthand side that's pushing my ASCII too far to the right. What's causing that to happen, and how can I get it nice and centered?
Image 1: Screenshot: config.el custom function
Image 2: Indented ASCII splash screen
Code below, sorry for the mess. It's also in the screenshot.
(defun custom_banner ()
(let* (
(banner
'(
" ▄████████ ▄████████ ▄████████ ▄████████ ▄████████ ▄███████▄ ▄████████ ████████▄ ▄████████ ▄████████ "
" ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀███ ███ ███ ███ ███ "
" ███ ███ ███ █▀ ███ █▀ ███ ███ ███ █▀ ███ ███ ███ ███ ███ ███ ███ █▀ ███ █▀ "
" ███ ███ ███ ▄███▄▄▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▄███▄▄▄ ███ "
" ▀███████████ ███ ▀▀███▀▀▀ ▀███████████ ▀███████████ ▀█████████▀ ▀███████████ ███ ███ ▀▀███▀▀▀ ▀███████████ "
" ███ ███ ███ █▄ ███ █▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ █▄ ███ "
" ███ ███ ███ ███ ███ ███ ███ ███ ▄█ ███ ███ ███ ███ ███ ▄███ ███ ███ ▄█ ███ "
" ███ █▀ ████████▀ ██████████ ███ █▀ ▄████████▀ ▄████▀ ███ █▀ ████████▀ ██████████ ▄████████▀ "
" "
" ▄████████ ▄▄▄▄███▄▄▄▄ ███ █▄ ███▄▄▄▄ ▄█ ▄█▄ ▄█ █▄ ▄████████ ▄███████▄ ▄████████ ▄████████ ▄████████ "
" ███ ███ ▄██▀▀▀███▀▀▀██▄ ███ ███ ███▀▀▀██▄ ███ ▄███▀ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ "
" ███ ███ ███ ███ ███ ███ ███ ███ ███ ███▐██▀ ███ ███ ███ █▀ ███ ███ ███ █▀ ███ ███ ███ ███ "
" ███ ███ ███ ███ ███ ███ ███ ███ ███ ▄█████▀ ▄███▄▄▄▄███▄▄ ▄███▄▄▄ ███ ███ ▄███▄▄▄ ▄███▄▄▄▄██▀ ███ ███ "
"▀███████████ ███ ███ ███ ███ ███ ███ ███ ▀▀█████▄ ▀▀███▀▀▀▀███▀ ▀▀███▀▀▀ ▀█████████▀ ▀▀███▀▀▀ ▀▀███▀▀▀▀▀ ▀███████████ "
" ███ ███ ███ ███ ███ ███ ███ ███ ███ ███▐██▄ ███ ███ ███ █▄ ███ ███ █▄ ▀███████████ ███ ███ "
" ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀███▄ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ "
" ███ █▀ ▀█ ███ █▀ ████████▀ ▀█ █▀ ███ ▀█▀ ███ █▀ ██████████ ▄████▀ ██████████ ███ ███ ███ █▀ "
" ▀ ███ ███ "))
(longest-line (apply #'max (mapcar #'length banner))))
(put-text-property
(point)
(dolist (line banner (point))
(insert (+doom-dashboard--center
+doom-dashboard--width
(concat line (make-string (max 0 (- longest-line (length line))) 32)))
"\n"))
'face 'doom-dashboard-banner))
)
(setq +doom-dashboard-ascii-banner-fn #'custom_banner)
If I had to guess, that function is not designed to work with banners as wide as yours. Note yours is a lot wider than the default and the examples given at the site you link in the comments.
Observe that +doom-dashboard--width is defined as 80, suggesting to me that you're not supposed to use a splash screen any wider than that. You could try just removing the call to +doom-dashboard--width and all the other centering logic, since your text is already pre-centered. Maybe it works, but no guarantees.
...
(dolist (line banner (point))
(insert line "\n"))
...
Related
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)
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)
//▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
}
//█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █
I created a program where picker shows upon clicking on my text field and I am trying to dismiss it when I click the "done" or "cancel" button on my toolbar.
I have no idea where it went wrong. Although it says
"2017-09-28 20:45:27.877897-0600 project1 [51296:5112470] [LayoutConstraints] Unable to simultaneously satisfy constraints."
All of my constraints are working fine atm..
Here is my code:
#IBOutlet weak var textField1: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
let picker: UIPickerView
picker = UIPickerView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 300))
picker.backgroundColor = .white
picker.showsSelectionIndicator = true
picker.delegate = self
picker.dataSource = self
let toolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 40))
toolBar.barStyle = UIBarStyle.default
toolBar.isTranslucent = true
toolBar.tintColor = .black
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action:
Selector(("donePicker")))
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: Selector(("donePicker")))
)
toolBar.setItems([cancelButton, spaceButton, doneButton], animated: true)
toolBar.isUserInteractionEnabled = true
let bgView = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 250 + toolBar.frame.size.height))
print(picker.frame.size.height, toolBar.frame.size.height, bgView.frame.size.height)
bgView.addSubview(picker)
bgView.addSubview(toolBar)
textField1.inputView = bgView
}
func donePicker() {
textField1.resignFirstResponder()
}
And this is the error that it gives me:
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-09-28 20:45:29.253610-0600 project1[51296:5112470] [MC] Lazy loading NSBundle MobileCoreServices.framework
2017-09-28 20:45:29.255001-0600 project1[51296:5112470] [MC] Loaded MobileCoreServices.framework
2017-09-28 20:45:29.274235-0600 project1[51296:5112470] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/Andrew/Library/Developer/CoreSimulator/Devices/EE44EDE5-BDF6-4A15-A44B-387E14685DAA/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
300.0 44.0 294.0
2017-09-28 20:45:30.401748-0600 project1[51296:5112470] [MC] Reading from private effective user settings.
2017-09-28 20:45:31.827410-0600 project1[51296:5112470] -[project1.CalculateViewController donePicker]: unrecognized selector sent to instance 0x7faac1d0fab0
2017-09-28 20:45:31.835746-0600 project1[51296:5112470] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[project1.CalculateViewController donePicker]: unrecognized selector sent to instance 0x7faac1d0fab0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c8a11cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010a93cf41 objc_exception_throw + 48
2 CoreFoundation 0x000000010c921914 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x000000010d4660bd -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x000000010c824178 ___forwarding___ + 1432
5 CoreFoundation 0x000000010c823b58 _CF_forwarding_prep_0 + 120
6 UIKit 0x000000010d23f9bd -[UIApplication sendAction:to:from:forEvent:] + 83
7 UIKit 0x000000010dc3353f __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 154
8 UIKit 0x000000010dc33470 -[_UIButtonBarTargetAction _invoke:forEvent:] + 181
9 UIKit 0x000000010d23f9bd -[UIApplication sendAction:to:from:forEvent:] + 83
10 UIKit 0x000000010d3b6183 -[UIControl sendAction:to:forEvent:] + 67
11 UIKit 0x000000010d3b64a0 -[UIControl _sendActionsForEvents:withEvent:] + 450
12 UIKit 0x000000010d3b53cd -[UIControl touchesEnded:withEvent:] + 618
13 UIKit 0x000000010d2b3d4f -[UIWindow _sendTouchesForEvent:] + 2807
14 UIKit 0x000000010d2b5472 -[UIWindow sendEvent:] + 4124
15 UIKit 0x000000010d25a802 -[UIApplication sendEvent:] + 352
16 UIKit 0x000000010db8ca50 __dispatchPreprocessedEventFromEventQueue + 2809
17 UIKit 0x000000010db8f5b7 __handleEventQueueInternal + 5957
18 CoreFoundation 0x000000010c8442b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x000000010c8e3d31 __CFRunLoopDoSource0 + 81
20 CoreFoundation 0x000000010c828c19 __CFRunLoopDoSources0 + 185
21 CoreFoundation 0x000000010c8281ff __CFRunLoopRun + 1279
22 CoreFoundation 0x000000010c827a89 CFRunLoopRunSpecific + 409
23 GraphicsServices 0x00000001122ee9c6 GSEventRunModal + 62
24 UIKit 0x000000010d23dd30 UIApplicationMain + 159
25 UofA Engineering Master 0x0000000109ffa307 main + 55
26 libdyld.dylib 0x000000010fbc5d81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I have tried a different approach to show PickerView and toolbar in textField.
Try this if it helps in your scenario:
let toolBar = UIToolbar()
toolBar.barStyle = UIBarStyle.default
toolBar.isTranslucent = true
toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action: #selector(CalculateViewController.donePicker))
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: #selector(CalculateViewController.cancelPicker))
toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
toolBar.isUserInteractionEnabled = true
textField1.inputView = pickerView
textField1.inputAccessoryView = toolBar
You can see the error message is:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[project1.CalculateViewController donePicker]: unrecognized selector sent to instance 0x7faac1d0fab0'
For Swift, we don't define the selector like that (it's Objective C way). You should use like this:
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action:
#selector(donePicker))
since the error is unrecognized selector sent to instance, you may let the picker become a property. replace the let picker: UIPickerView out of the viewdidload method with var picker: UIPickerView?
I am trying to animate a change of color of a navigation bar when popping back to a previous controller. To give it some context, I have controller A which is a collectionView Controller and has an opaque navigation bar color set by:
self.navigationController?.navigationBar.barTintColor = UIColor.rgb(red: 244, green: 67, blue: 54)
self.navigationController?.navigationBar.tintColor = .white
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
self.navigationController?.navigationBar.isTranslucent = false
Once a collectionViewCell is selected I push to the next controller, B, where the navigation bar is altered to become transparent:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
When a user taps on the back arrow, I want the navigationBar to return to it's original colors. I have tried a simple UIView animation on the controller B's viewWillDissappear function, willMove(toParentViewController) and the viewWillAppear function on Controller A:
Here is the animation:
UIView.animate(withDuration: 0.5) {
self.navigationController?.navigationBar.barTintColor = UIColor.rgb(red: 244, green: 67, blue: 54)
self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
self.navigationController?.navigationBar.shadowImage = nil
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.layoutIfNeeded()
}
After doing this I tried using a transition coordinator but got the same results:
guard let coordinator = self.transitionCoordinator else {
return
}
coordinator.animate(alongsideTransition: {
[weak self] context in
self?.navigationController?.navigationBar.barTintColor = UIColor.rgb(red: 244, green: 67, blue: 54)
self?.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
self?.navigationController?.navigationBar.shadowImage = nil
self?.navigationController?.navigationBar.isTranslucent = false
self?.navigationController?.navigationBar.layoutIfNeeded()
}, completion: nil)
It seems that no matter what I try, or where I put the code I always end up with the same outcome. I am aware that the code is repetitive, but I was just trying to figure out why, so a lot of copying and pasting occurred.
From what I can tell, I think that it has something to do with the background view of the previous controller, but I am stumped, I seem to see a black screen before the animation under the navigation bar. Any help would be greatly appreciated.
Thanks
Details
xCode 8.3.2, swift 3.1
Solution
override func viewWillAppear(_ animated: Bool) {
if let navigationBar = self.navigationController?.navigationBar {
navigationBar.backgroundColor = .blue
}
}
Full sample
ViewController
import UIKit
class ViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
if let navigationBar = self.navigationController?.navigationBar {
navigationBar.barTintColor = UIColor(red: 244/255, green: 67/255, blue: 54/255, alpha: 1.0)
navigationBar.tintColor = .white
navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
navigationBar.isTranslucent = false
}
}
}
ViewController2
import UIKit
class ViewController2: UIViewController {
override func viewWillAppear(_ animated: Bool) {
if let navigationBar = self.navigationController?.navigationBar {
let color = UIColor(red: 1, green: 153/255, blue: 0, alpha: 1.0)
navigationBar.setBackgroundImage(UIImage.imageWithColor(color: color), for: .default)
navigationBar.shadowImage = UIImage()
navigationBar.isTranslucent = true
}
}
override func viewWillDisappear(_ animated: Bool) {
if let navigationBar = self.navigationController?.navigationBar {
navigationBar.setBackgroundImage(nil, for: .default)
navigationBar.shadowImage = nil
navigationBar.isTranslucent = false
}
}
}
extension UIImage
import UIKit
extension UIImage {
class func imageWithColor(color: UIColor) -> UIImage {
let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
UIGraphicsBeginImageContextWithOptions(CGSize(width: 1, height: 1), false, 0)
color.setFill()
UIRectFill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
}
Main.storyboard
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Tzy-ol-uu0">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="stackowerflow_44343355" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="eIC-Nm-Ex7">
<rect key="frame" x="164" y="318" width="46" height="30"/>
<state key="normal" title="Button"/>
<connections>
<segue destination="QHs-H4-fAS" kind="show" id="Rff-Eq-K6g"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="eIC-Nm-Ex7" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="G1g-VM-MAn"/>
<constraint firstItem="eIC-Nm-Ex7" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="mdZ-GP-EQw"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="hq3-zt-U4K"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="977" y="791"/>
</scene>
<!--View Controller2-->
<scene sceneID="F9C-Nz-6dd">
<objects>
<viewController id="QHs-H4-fAS" customClass="ViewController2" customModule="stackowerflow_44343355" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="AV0-X8-nhX"/>
<viewControllerLayoutGuide type="bottom" id="AsY-Gl-67v"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="1fA-pX-rzR">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Uzd-Tb-KRO" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1770" y="789"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="Jff-OO-3e7">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="Tzy-ol-uu0" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="804-YF-T6T">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="BRB-ym-7I2"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="M6i-ib-61I" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="140" y="791.15442278860576"/>
</scene>
</scenes>
</document>
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.