button图片与文字的布局

本文介绍如何通过调整UIButton的titleEdgeInsets和imageEdgeInsets属性来优化按钮上图片与文字的布局,并提供了具体的代码实现。同时,文中还提到了一些常见的错误示例及解决办法。

button选择adjusts会影响代码对button图片与文字的布局

////注意:width要比height大,否则就替换

button.titleEdgeInsets = UIEdgeInsetsMake(0,-(button.currentImage?.size.width)!, (button.titleLabel?.intrinsicContentSize.height)! - button.height()/2, 0)

button.imageEdgeInsets = UIEdgeInsetsMake(-(button.titleLabel?.intrinsicContentSize.height)!, 0, 0, -(button.titleLabel?.intrinsicContentSize.width)!)

 

 

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x141d09110> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key notiSubtitleLabel.'

连线的时候注意选择,不要选择firstResponse,要选择这个类的名字。

!!! 连线之后不要修改,如果需要修改,要重新写xib文件以及类文件,要不然就会报上面的错,不重新写文件很难找到问题

图片导入不显示,B一下,还不能显示清缓存,  再不行删除后重新导入

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值