案例:
X2设备上,UIButton图片遭截; X3设备上没有这种问题.
设置代码如下:
self.likeBtn = [[UIButton alloc] init];
[self.likeBtn setImage:[UIImage imageNamed:@"praise"] forState:UIControlStateNormal];
[self.likeBtn setImage:[UIImage imageNamed:@"praised"] forState:UIControlStateSelected];
[self.contentView addSubview:self.likeBtn];
[self.likeBtn setTitle:@"0人赞" forState:UIControlStateNormal];
self.likeBtn.titleLabel.font = [UIFont systemFontOfSize:15];
[self.likeBtn setTitleColor:UIColorFromRGB(0x1f1f1f) forState:UIControlStateNormal];
self.likeBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 3.75, 0, -3.75);
self.likeBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -3.75, 0, 3.75);
self.likeBtn.contentMode = UIViewContentModeRight;
[self.likeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.shareBtn);
make.right.equalTo(self.separateLine.mas_left).offset(-15-margin);
make.height.mas_equalTo(self.likeBtn.intrinsicContentSize.height + 30);
}];
[self.likeBtn addTarget:self action:@selector(likeBtnDidClicked:) forControlEvents:UIControlEventTouchUpInside];
分析:
很有可能3.75的像素点无法精确至一个像素点,导致部分像素被截了.
解决:
取整
self.likeBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -ceil(3.75), 0, ceil(3.75));