ios - Resize parent UIView based on its children size -
i'm new in ios programming , still don't know how handle correctly basic stuff hope has practice share.
i created custom keyboard user reply question. it's uiview containing uibutton.
how 1 center whole keyboard?
i know calculate width of keyboard adding width of each key seems quite complicated such simple action.
here's code (in swift) now, thanks.
keyboardcontainer = uiview(frame: cgrectmake(0, 0, self.frame.width, 200)) keyboardcontainer!.center = cgpoint(x: keyboardcontainer!.frame.width / 2, y: self.frame.height - keyboardcontainer!.frame.height / 2) self.addsubview(keyboardcontainer!) allow gap = int(self.frame.width) / 8 in 0..<keyboardletters!.count { allow posx = int(i % 7) * gap + 22 allow posy = int(i / 7) * gap + 25 allow key = key(frame: cgrectmake(0, 0, 44, 44)) key.letter = keyboardletters![i] key.tag = key.center = cgpoint(x: posx, y: posy) keyboardcontainer!.addsubview(key) key.addtarget(self, action: "onkeyboardtap:", forcontrolevents: .touchupinside) }
move center of keyboardcontainer
, buttons move it.
ios uiview swift centering
No comments:
Post a Comment