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.

Sunday, June 12, 2016

About AutoLayout and ScrollView

Not sure if you have trapped into this issues, but I have when I try to use scrollView and put something inside it using Interface Builder. I found all are not work as usual. and this article helps me out, find tricks to resolve the problem.

https://www.natashatherobot.com/ios-autolayout-scrollview/ 

 The key points are:
1, The ScrollView should have only ONE child view.
2, Adding an Equal Width constraint between the main View and the ContentView

welcome any comments and sharing

Friday, April 22, 2016

Something important you may ignore about UITableView - static cells

Surely, lots of people knows the convenience of leverage UITableView to generate dynamic cell, that's the default setting of UITableView for cell.

But something you maybe fine it's another "hidden" magic is "static cell".

So, what we can get from the static cell ?
Simply like a Sign In or Sign Up page. table handling the row format for you and scrollable for you.
you just put cell and use, avoiding datasource or delegate settings in UITableViewController, for it's static, so just drag it to nib file and use, that's all.

no need "grouped" in order to show just the number of rows you want, for static cell it won't show more useless line, you even can hide the separate line easily, good one right?

Wednesday, April 20, 2016

Serverless, the future

Recently I've fallen in love with AWS.

So powerful and keeping bring new things. The serverless concept is so great and shows lots of new future.

After days struggling, I notice maybe serverless guys forget to provide a user pool for sign in or sign up function to work with cognito. but finally I found they have a beta version for that already LoL.

http://docs.aws.amazon.com/cognito/latest/developerguide/setting-up-cognito-user-identity-pools.html

after they provide "authentication" servers, serverless are more perfect and easy to became want to be AWS's "slave"

Leverage AWS Mobile Hub to create backend services in fly

Personally, I'm a lazy nerd, So Mobile hub let me jump up.

But when start to deal with this Great guy, I can feel lots of inconvenient.

Unknow is the most thing scale developer special nerd.

So, finally I have a decision and direction of how to leverage the powerful mobile hub to help me but in my way.

1, can be use to build demo or sample
2, can be use to config backend services
3, to peek the great guys behind mobile hub to learn how to deal with swift projects :)

Sunday, April 17, 2016

AWS Mobile Hub - Rename project issue

Recently, I'm trying AWS Mobile Hub to "click-to-create-app". It's amazing, as a sample or quick start, definitely should consider it.

But, what's the next? You're going to start your own one, like me. Then I occur something boring, to rename the project.

also AWS also share a link from Apple of how to rename project, but Mobile Hub has something more need to be handled. Personally, After I fixed my project, I feel maybe Mobile Hub guys need to improve their way.

I'm sharing my issues and how I work through them here. Any better ideas are welcome.

0, I try to add my "project name" as Mobile Hub prompt me, but just to me MySampleProject project when I download, I think that's not good enough. Giving me the exact project name as I specify "project name" is perfect I think.

1, Rename as Apple recommend, and also the bundle ID
https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/RenamingaProject/RenamingaProject.html

2, But that's far not enough for developer to start their own one, for we're very "straight" sometimes. There are still too much "MySampleApp" existing in this project and that's unacceptable even you can run it already. Code need to be beautiful enough so we can have a good mood :)

3, So, Rename the physical folder name to "xxx" (e.g.), and open .proj file and remove the "MySampleApp" and add your need folder name. (for after you rename the physical folder, reference are broken, so you need to delete the old one and add the new one)

4, Do a search of "MySampleApp", and fix the search framework path etc.

5, Go to build phrases, to check script and embedded frameworks to fix them

6, This part is not that obvious to notice until your run and your app crashed. The sample project enabled the "module" function, and this remain the old "MySampleApp" as module name for each controller and some cells, so you need to open storyboard and check every controller and cells or others to remove the module name. (enable module is maybe not a good way, hope Mobile Hub guys and have a better or improved solutions)

Finally, you got there, run and no crash, everything is fine.

Good Luck!




Tuesday, April 5, 2016

UIScrollView + UIPageControl = pagable Ad. Bar or start-up presentation for your app

Parse vs. AWS (Mobile Hub), The Decision

Knowing Parse is going down, surprising me somehow but not surprising me somehow.

I'm a Parse fan, free resource let me fell in love with Parse.

After a period of "high speed" growth of Parse, and then I can feel Parse are changing to be silence.

High speed is a good thing, but expanding horizontal too much wide to lose its way and focus.
cloud code is a great thing, but I can say it's so difficult to use. Maybe they can put 50% effort on this then can save not be like now.

After struggling again and again, finally I decide to move to AWS. I've tried China's Aliyun Cloud Service, too. But After I paid my money for a instance for Aliyun and get into the management, I decided to give up and continue to use AWS in seconds. Maybe Aliyun is still on its way of growing or maybe AWS are just too powerful to be compared with.

Anyway, The decision is made, moving to AWS

Monday, April 4, 2016

iOS app, using Xcode to create Multiple target with localized plist file

Recently, I need to create another "free version" for my existing app like most of other people, business need.

After some struggling and researching, I found a solution but the guide are very unclear. So I think it's better to post one for myself, in case I have to struggle again and also for does are still struggling.

For you do have one existing target, let's say it's name is testapp, and now you want another one, according apple develop center's doc I believe you can find something more useful than I descripte it here, so I will just skip "duplication and rename the build target" part.

roughly steps:
1, in Xcode, duplicate your build target
2, rename your build target
3, rename your xxx-Info.plist file to what you want, in my case I use testapp-free-Info.plist
4, go to "Build Setting" to rename the plist reference, so that you can view your plist while click the "Info" tab.

let's continue to create localizing file for our new build target

5, add a new .strings file and name it to "InfoPlist.strings". ( One thing I still double if could I rename this, I only can success when using the default name. if anyone know how to use a custom name for multiple targets, please share your great tricks :))

6, So, make sure you add a new .strings with the name "InfoPlist.strings" and put it to different location of your old target, for both targets new using the same localized file name.

7, Then the left is sample as usual, just localized your .strings file.

Saturday, April 2, 2016

About UITableViewController

Everytime when you have your tableView grouped, you will see some margin on the top of the table, I'm not quite sure yet, but I think that's the headerView of the tableView.

So, after I set a UIView to tableView's headerView, then the margin was gone or as the height as I want.

something like this

self.tableView.tableHeaderView = UIView(frame: CGRectMake(0,0,self.tableView.frame.width,1))

Simple and Nice.

About UICollectionViewController

Recently, I tried to use a UICollectionViewController to show some buttons, I thought it shouldn't be difficult, for I heard lots of people said it's very similar to UITableViewController, and one thing let me struggling a little long.

A good way to show buttons in a nice layout. It turns out the UICollectionViewController's layout has some default values for some properties.

let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
layout.sectionInset = UIEdgeInsets(top: 2, left: 2, bottom: 2, right: 2)
layout.itemSize = CGSizeMake((self.view.frame.width-8)/3,(self.view.frame.width-8)/3)
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 2


if you don't want any margin for your cell, you need to override below two properties, for the default value is 10.

layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0

Sunday, March 20, 2016

iOS, Storyboard vs. nib or xib file

OK, after sharing some moments of my feeling, let's back to face the "work".
After some researching, I believe Storyboard are a great thing which I haven't noticed before. Of course, this doesn't mean nib or xib file is a bad way for building a project.

Mix Storyboard and nib or xib file or even pure code something is the best practice I believe now. (Not sure in the near future what will happen :) )

Sharing your experience or issue occurred in your project your life here if you have, let's learning from each other.  :)

Beginning my new lifestyle

I'm a IT guy like most of people, I like coding and reading technical articles.

I'm starting to try out the lifestyle I like or I wish, but maybe ever noticed by myself. Unknowing is kind of bad feeling and normally making people unhappy, finally give up the choice they've made at the beginning or when they said so surely.

Time change people, change their mind, change who their are, and finally you forget who your are and became someone new. Of course, someone is better and someone is worst. But in this moment, I just want to share about myself, for me, I think I was the later one. That's why I decide to search my new lifestyle or get my "Old" lifestyle back.

Like most of people, the beginning and strongest feeling for this kind of guy is confusing. But I'm lucky to have my old family around me or with me, and unlucky it seems less the same kind of me around me, around my area, around my city.

So, I decide to share some through internet, and to find those like me around the world, I believe lots of "me" in this world.

Wish me luck!

:)