Thursday, November 10, 2016

[ Google Blogger, code snippet formatting ]I've never thought that I will be so struggling when sharing code snippet in Google's Blogger

Sometimes, and write blogs, but when I come to share some code snippets in Google's Blogger, I've never thought that I will be so struggling, just for such simple thing. Maybe there are better  and simple ways to do that or I really hope google guys really need to fix this ASAP.

Something supprise me evern more that after lots of google searching, I still can not get better solution that I can agree with. Neither too complex nor simple enough.

Eventually, I wrote a simple html5 with some css snippet, and it seems not that bad. Simple enough.

I'd like to share what I'm using and see if anyone has better solution, I'm very glad to know and use a better one.

Making life simpler, why not.

Be careful, you need switch to "HTML" mode before you paste below code, then switch back to "Compose" mode to see how it looks like.

<div style="background-color: #e6ffee; font-size: 15px; overflow-x: scroll; overflow-y: scroll;">
  <pre>
    put your code here
  </pre>
</div>

Finally, I also share more two links here so that you can try out your prefer style.
( from http://www.w3schools.com/ )
HTML editor
Color picker

iOS Keyboard show & hide tricks

Almost all app needs text input function, means all need to handle the keyboard show and hide issues.

My rough idea is as below steps:

1, adding an outlet of bottom constraint to the view that you want to scroll up when keyboard shows or hides.
    @IBOutlet weak var bottomConstraint: NSLayoutConstraint!

2, setting up to get keyboard show or hide notifications
    override func viewWillAppear(_ animated: Bool) {
        NotificationCenter.default.addObserver(self, selector:#selector(keyboardWillShow(notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        NotificationCenter.default.removeObserver(self)
    }

3, handling when notification fired.
    func keyboardWillShow(notification:Notification) {
        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
            self.bottomConstraint.constant = keyboardSize.height
        }
    }
    
    func keyboardWillHide(notification:Notification) {
        self.bottomConstraint.constant = 0
    }

just that simple