Make the UITableView with group style to round the image.

The point is, the roundCorner is draw by a subview of UITableViewCell, and mean while, it’s not a public class, there is no way you can get layer.cornerRadius from any view. So we need to resolve this problem by ourselves.

There are 2 cases.

  1. There is only one cell.

    This case is ease, just use cell.contentView.layer.cornerRadius and cell.contentView.layer.masksToBounds to make it work.

  2. There are more than one cell.

    This case is a little bit difficult. We need to deal each cell separately. Use the cell.contentView.layer.mask property to make it work. The first cell and the last cell has different round corner position. So draw the path and make it work.

Which direction is `UIImageOrientationUp`

UIImage has a good property named imageOrientation, all the images taken by iPhone/iPad is stored in physical orientation, when draw it on the view, most of the UIKit API and CoreGraphic API can recognize the orientation and render it it correct orientation. But if you need to resize the image or do some effect on the image by yourself, you need to calculate the image orientation by yourself. Thus you MUST understand which direction is UIImageOrientationUp.

The possible orientations

The UIImage header file defined the orientations as:

typedef enum {
    UIImageOrientationUp,            // default orientation
    UIImageOrientationDown,          // 180 deg rotation
    UIImageOrientationLeft,          // 90 deg CCW
    UIImageOrientationRight,         // 90 deg CW
    UIImageOrientationUpMirrored,    // as above but image mirrored along other axis. horizontal flip
    UIImageOrientationDownMirrored,  // horizontal flip
    UIImageOrientationLeftMirrored,  // vertical flip
    UIImageOrientationRightMirrored, // vertical flip
} UIImageOrientation;

Fine, it is commented, but, hmm, no so well. Could you tell me which direction is the UIImageOrientationUp?

The UP orientation

It’s not the orientation when you hold your iPhone in the normal mode. Make a guess!

OK, I know your guys are not so patient, so,

Here is the correct answer: this orientation is the UP!

The UP orientation when you take a photo on iPhone

Fibonacci Number

Fibonacci Number is a very common topic in everyday life, because it has a tight relationship with golden ratio Φ(Phi).

In CS, calculate the nth fibonacci number is also an interesting problem. Here is a Lightening Talk I gave to my company’s engineer on March 22, 2012. Take a look at it if you are looking for a job now, or you just don’t know how to calculate a fibonacci number.


Meanwhile, don’t forget to follow me on twitter, or on Facebook

Tips – Using janus to manage your Vim settings.

What is janus?

From janus‘s official Github page:

This is a distribution of plug-ins and mappings for Vim, Gvim and MacVim.

Just as it statement says, it packaged some popular plug-ins and mapping for you, so you can to use a full featured Vim after you installed Vim(If you are using Mac and Lion+, that means you just need to run a command and start to use a luxury Vim).

If you are in a rush, just copy the line below and paste to your terminal.

$ curl -Lo- http://bit.ly/janus-bootstrap | bash

Why bothering janus?

There are many famous plug-ins for Vim. But searching and installing plugins could be a painful work.

Usually, you google it, then go to vim.org to download it, then you config it and use it. This process is fine for one plugin, what if you want to install the top 10 vim plugins for coder, what if you want to install another 10 popular plugins?

For me, I can’t go through this process again and again. Don’t even think about the weird errors popped out when you installing your plugins.

What’s the merit I can get?

With janus, all you need to know is run a command and then use it. Oh, maybe you still need to remember some command for the plugins.

Where to start?

If you have enough patient to read to here, I suggest you to take a look at janus’s Github page.

What? you just want to use it? OK, open your terminal and paste the code below.

$ curl -Lo- http://bit.ly/janus-bootstrap | bash

Good luck!

And, don’t forget to follow my twitter @TonnyXu