美文网首页
UIButton addSubView添加到UIView 无效的

UIButton addSubView添加到UIView 无效的

作者: 萨缪 | 来源:发表于2020-04-06 20:38 被阅读0次

    今天在一个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