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

Tuesday, October 18, 2016

Easier maintenance UI with Interface Builder ? Your First Choice StackView

Don't struggling anymore, try to think with StackView as possible as you can.

Checking out WWDC about StackView to save your life.

Present a transparent background ViewController easily from iOS 8

Before iOS 8, when you think you can simply present a transparent background color view controller, then you just get disappointed.  After days struggling you give up and write your own one. That's true, iOS havn't that.

But from iOS 8, you can present a transparent background color viewcontroller as you usual do, by adding one more magic code.


myModalViewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext

then present it. Done :)

Sunday, September 11, 2016

About debugging constraint

http://staxmanade.com/2015/06/debugging-ios-autolayout-issues/

This article describe a nice and easy way to find out where's your constraints get wrong.

If you are also facing the same problem and struggling, I recommend you read through above article,

if you still can not get through your issue, welcome to leave your comment or sharing your great way if you have or found.

the points are:

1, Open the Breakpoint Navigator cmd+7
2, Click the Add button in the lower left
3, Select Add Symbolic Breakpoint...
4, Where it says Symbol just type in UIViewAlertForUnsatisfiableConstraints


after above actions, you should be able to be stopped when any issue constraint occurs.
then you use
po 0x7fc82aba1210
to trace-back to the View by its address.

when the info is not enough you can try to get more wtih:
po [0x7fc82aba1210 recursiveDescription]
or 

po [[0x7fc82aba1210 superview] recursiveDescription]

And maybe you will still get lost in this black-hole, you can try to track-back by the Thread, when in debug mode, it stop at the first occurred breakpoint, and you can track-back to see in which view it happens.

Thanks

Thursday, July 7, 2016

Tips: Transparent NavigationBar

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.shadowImage = [UIImage new];

Monday, June 20, 2016

Tips: ImageView with AspectFill settings

Recently, I met a small issue of when setting imageView with aspectFill, then images became the original large then break the view's layout. special when use scrollView's pagination you will want a picture for one page. And my trick to working around this is set the "clip subview" for parents view of that imageView. so that you can have just one page for a aspectFill setted imageView nicely. Welcome to share your tricks anytime.