I am trying to make a word puzzles solving game. For that I need the UI elements like in this image:
To achieve this i have created UIImages programmatically and added according to the answer. My code looks something like this
func startGame(ans:String){
assert(ans.characters.count > 0 , "Answer is NILL")
let word1 = ans as String
let spacesRemovedString = word1.stringByReplacingOccurrencesOfString(" ", withString: "")
let word2 = returnRandomStringwithAnswer(spacesRemovedString)
print(word2.uppercaseString)
//calculate the tile size
let tileSize = ceil(viewForTargets.bounds.width * 0.4 /
CGFloat(word1.characters.count)) - TILE_MARGIN
(CGFloat(word1.characters.count)) " + " \(tileSize +
TILE_MARGIN))")
//get the left margin for first tile
var xOffset = (viewForTargets.bounds.width -
CGFloat(word1.characters.count) * (tileSize + TILE_MARGIN)) / 2.0
//adjust for tile center (instead of the tile's origin)
xOffset += tileSize / 2.0
//create targets
for (index, letter) in word1.characters.enumerate() {
//if the word having more then 8 characters create 2 lines
if word1.characters.count > 8 {
//TODO
}else{
//if space present skips making a target
if letter != " " {
let target = TargetView(letter: letter, sideLength: tileSize)
target.center = CGPointMake(xOffset + CGFloat(index)*(tileSize + TILE_MARGIN), viewForTargets.bounds.height / 3.5)
//target.translatesAutoresizingMaskIntoConstraints = false
//ads target to viewForTargets
viewForTargets.addSubview(target)
targets.append(target)
}
}
}
}
I thought this would work but real tragedy started here, when i run the programme it is getting something like this which i don't want to be.
i thought my code was wrong and have done lot of debugging and finally find out my code is correct when i rotate the simulator to landscape.
i want this game only on portrait mode but i have no idea how to make the ui which i have shown in the first image. Please help me to achieve this
Thanks for the help.