Swift 4.0 Xib实现Button调整

1.Xib画的界面按钮,代码中进行调整按钮图片在上,文字在下:

代码中修改按钮的位置比较好:

 

        payButton.titleEdgeInsets = UIEdgeInsetsMake((payButton.imageView?.height)! + 20, -(payButton.imageView?.width)!, 0, 0)
        payButton.imageEdgeInsets = UIEdgeInsets(top: -20, left: 0, bottom: 0, right: -(payButton.titleLabel?.bounds.width)!)
        businessButton.titleEdgeInsets = UIEdgeInsetsMake((businessButton.imageView?.height)! + 20, -(businessButton.imageView?.width)!, 0, 0)
        businessButton.imageEdgeInsets = UIEdgeInsets(top: -20, left: 0, bottom: 0, right: -(businessButton.titleLabel?.bounds.width)!)
        systemButton.titleEdgeInsets = UIEdgeInsetsMake((systemButton.imageView?.height)! + 20, -(systemButton.imageView?.width)!, 0, 0)
        systemButton.imageEdgeInsets = UIEdgeInsets(top: -20, left: 0, bottom: 0, right: -(systemButton.titleLabel?.bounds.width)!)
        changeButton.titleEdgeInsets = UIEdgeInsetsMake((changeButton.imageView?.height)! + 20, -(changeButton.imageView?.width)!, 0, 0)
        changeButton.imageEdgeInsets = UIEdgeInsets(top: -20, left: 0, bottom: 0, right: -(changeButton.titleLabel?.bounds.width)!)

 

总结:

1.要熟练掌握StoryBoard和Xib的约束,如果项目最低适配9.0,Xib里可以使用UIStackView,设置约束和适配很是方便;

2.特殊的约束可以在代码里修改,方便和直观;

新公司项目使用的Swift + Ipad开发,最近都在忙着做国际化和适配问题,对于Swift并不特别熟练的我要学习的还有很多,后面会一一更新自己项目中的难点和值得学习的点,记得关注思思哟。

欢迎关注思思个人公众号“思思小窝”哟,了解思思动态,哈哈😆

posted on 2018-04-05 09:00  玉思盈蝶  阅读(448)  评论(0编辑  收藏  举报

导航