今天在一个VC中新建一个UIView 然后再新建一个UIButton 想把button通过addSubView的方式添加到View上 但是总是失败
查了半天才吵到原因 是button的frame设置有误
之前的设置:
self.demoButton.frame = self.demoView.frame;
这样直接用父view的frame是错误的
应该
self.demoButton.frame = self.demoView.bounds;
这样就能成功添加上了
今天在一个VC中新建一个UIView 然后再新建一个UIButton 想把button通过addSubView的方式添加到View上 但是总是失败
查了半天才吵到原因 是button的frame设置有误
之前的设置:
self.demoButton.frame = self.demoView.frame;
这样直接用父view的frame是错误的
应该
self.demoButton.frame = self.demoView.bounds;
这样就能成功添加上了
本文标题:UIButton addSubView添加到UIView 无效的
本文链接:https://www.haomeiwen.com/subject/akdiphtx.html
网友评论