我創建的UIView和按鈕編程Add按鈕的UIView創建編程
var width = self.view.frame.width - 8
var height = width/8
newView.frame = CGRectMake(4, 39, width, height)
newView.backgroundColor = UIColor.greenColor()
self.view.addSubview(newView)
var button = UIButton.buttonWithType(UIButtonType.System) as! UIButton
button.frame = newView.frame
button.backgroundColor = UIColor.whiteColor()
button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
button.setTitle(" All Hospitals/Clinics", forState: UIControlState.Normal)
button.setTitleColor(UIColor.blackColor(), forState: .Normal)
button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left
newView.addSubview(button)
我希望按鈕是UIView的內部,並具有完全相同的位置,寬度和UIView的
的高度但結果是這樣的
什麼是錯我的代碼?
在此先感謝
? –
@ SohilR.Memon是的我正在使用autolayout,但我需要這個按鈕被編程創建 – Maha
然後,你必須在編程創建UI時也給出約束! –