ios - Swift:How can i set button at the end of View Programmatically -
on button click have set uiwebview programmatically.
if(button.tag = 1) { let webv:uiwebview = uiwebview(frame: cgrectmake(10, 80, (uiscreen.mainscreen().bounds.width)-20, (uiscreen.mainscreen().bounds.height)/2)) webview.loadhtmlstring(html!, baseurl: nil) let button = uibutton(frame: cgrect(x: 100, y: 100, width: 100, height: 50)) button.backgroundcolor = .greencolor() button.settitle("test button", forstate: .normal) button.addtarget(self, action: #selector(buttonaction), forcontrolevents: .touchupinside) webview.addsubview(button) self.view.addsubview(webv) } i tried set button @ end of webview , not able set. tried many time still in progress. want set button @ end of webview have created programmatically.
use bounds property of parent view position subview.
let bottommargin = cgfloat(50) //space between button , bottom of screen let buttonsize = cgsize(width: 100, height: 50) let button = uibutton(frame: cgrect( x: 0, y: 0, width: buttonsize.width, height: buttonsize.height )) button.center = cgpoint(x: parentview.bounds.size.width / 2, y: parentview.bounds.size.height - buttonsize.height / 2 - bottommargin)
Comments
Post a Comment