I am trying to write my first iOS program and I need to display a matrix of letters and move its vertical lines separately because this matrix of letters is larger than the screen itself.
I would like these letters to be evenly spaced both in horizontal and vertical directions regardless what the actual letter is. i and y have different widths and o and b have different heights. What I am looking for is to have a table and each letter occupies a single cell.
First, I choose UILabel to display the individual vertical lines, because this way I can animate the lines. However, with the labels the l开发者_如何学JAVAetters are not distributed evenly.
Is there a way to tell the individual letters in a UILabel to occupy x amount of width regardless of the width of an actual letter?
Is there a better control or view in iOS to construct a matrix of letters and still be able to move its vertical lines separately?
Very quick answer: Use a fixed width font, like Courier, which spaces all letters equally.
You should definetly think about a programmatic way. If you do this with interface-builder you do exactly what it is not meant for: Expensive point and click adventures!
Just create a UILabel within a specific size, create the next, next, next, next, and then you move to the next line. I hopefully don't have to explain to you how that works. And keep in mind, that you create them in loadView !!!! ^^
- Create one UILabel for each letter
- Make all labels the same width and height
- Set textAlignment to UITextAlignmentCenter
- Distribute them evenly in your grid
精彩评论