我创建的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时也给出约束! –