您的位置:首页 > 其它

圆点view被切掉一块的bug

2017-08-10 10:07 441 查看
需要实现有新消息提醒时在title的右上角有红点提示,一个本来很简单的功能,但是遇到一个很奇葩的问题,有一个红点在6、6p上显示,红点的右边会有一点点被切平了,但是其他的几个红点是好的。真是一个很无语的bug啊

FUCK YOU MONEY

然后我就只能去跟这个bug,看看在3d视图显示上是啥样的,看了后发现,哈,真圆,圆的不能再圆了。

这里是模拟器上的图片,是没有问题的。真机上才会有。



此处略去找问题的艰辛…(10000字)

最后经过我的不懈努力,终于找到问题解决的办法

button.redDotView.center = CGPointMake(nearbyint(CGRectGetMaxX(button.titleLabel.frame)), CONTENT_PIXEL(65));


在设置红点的center的时候取整一下,就解决了

想想原因应该是苹果本身屏幕分辨率的问题

以后再遇到这类问题也算是有一个解决方案了

下面是自定义的一个公共类视图

#import "CETCHomeButton.h"

@implementation CETCHomeButton

- (void)setSelected:(BOOL)selected{
[super setSelected:selected];
if (selected) {
self.backgroundColor = [UIColor groupTableViewBackgroundColor];
}else{
self.backgroundColor = [UIColor whiteColor];
}
}

- (void)setHighlighted:(BOOL)highlighted{
[super setHighlighted:highlighted];
[self setSelected:highlighted];
}

- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];

}
return self;
}

- (UIImageView *)imageView{
if (!_imageView) {
_imageView = [[UIImageView alloc]init];
_imageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:_imageView];
}
return _imageView;
}

- (UIImageView *)bgImageView{
if (!_bgImageView) {
_bgImageView = [[UIImageView allo
b7c0
c]init];
[_bgImageView sendSubviewToBack:self];
[self addSubview:_bgImageView];
}
return _bgImageView;
}

- (UILabel *)titleLabel{
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]init];
_titleLabel.textColor = CETC_GRAY_COLOR;
_titleLabel.font = FONT_WITH_SIZE(15);
_titleLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:_titleLabel];
}
return _titleLabel;
}

- (UILabel *)detailLabel{
if (!_detailLabel) {
_detailLabel = [[UILabel alloc]init];
_detailLabel.textColor = CETC_LIGHT_GRAY_COLOR;
_detailLabel.font = FONT_WITH_SIZE(CONTENT_PIXEL(7));
_detailLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:_detailLabel];
}
return _detailLabel;
}

- (UIView *)redDotView{
if (!_redDotView) {
_redDotView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 8)];
//      _redDotView.layer.masksToBounds = YES;
_redDotView.layer.cornerRadius = 4.f;
_redDotView.backgroundColor = CETC_RED_COLOR;
[self bringSubviewToFront:_redDotView];
[self addSubview:_redDotView];
}
return _redDotView;
}

下面是调用的

for (NSInteger i = 0; i < buttonList.count; i ++) {
CETCHomeButton *button = [[CETCHomeButton alloc]initWithFrame:CGRectMake((buttonW + 1)* i, 0, buttonW, cellHeight)];
button.tag = 101 + i;
[button addTarget:self action:@selector(buttonsAction:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:button];

button.imageView.frame = CGRectMake(buttonW/2 - CONTENT_PIXEL(17), CONTENT_PIXEL(20), CONTENT_PIXEL(34), CONTENT_PIXEL(34));
button.titleLabel.frame = CGRectMake(0, CONTENT_PIXEL(65), buttonW, CONTENT_PIXEL(15));
button.detailLabel.frame = CGRectMake(0, CONTENT_PIXEL(85), buttonW, CONTENT_PIXEL(15));
button.detailLabel.font = FONT_WITH_SIZE(CONTENT_PIXEL(9));
button.detailLabel.adjustsFontSizeToFitWidth = YES;
button.titleLabel.font = FONT_WITH_SIZE(CONTENT_PIXEL(15));

NSDictionary *buttonDict = buttonList[i];
button.imageView.image = [UIImage imageNamed:buttonDict[@"image"]];
button.titleLabel.text = buttonDict[@"title"];
button.detailLabel.text = buttonDict[@"detail"];

[button.titleLabel sizeToFit];
button.titleLabel.centerX = buttonW/2;

button.redDotView.center = CGPointMake(nearbyint(CGRectGetMaxX(button.titleLabel.frame)), CONTENT_PIXEL(65));
button.redDotView.hidden = YES;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: