美文网首页移动开发
UIButton图片遭截问题

UIButton图片遭截问题

作者: iDeveloper | 来源:发表于2017-09-16 19:08 被阅读3次

案例:

X2设备上,UIButton图片遭截; X3设备上没有这种问题.

被截的UIButton

设置代码如下:

        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));
修改后的UIButton

相关文章

网友评论

    本文标题:UIButton图片遭截问题

    本文链接:https://www.haomeiwen.com/subject/gjucsxtx.html