按钮的image图片是非圆角,直接对UIButton设置圆角,iOS13系统没有圆角的效果的问题。iOS9和iOS14都没有这个问题。
self.layer.cornerRadius = cornerRadius;
self.layer.masksToBounds = YES;
解决方案:直接对按钮imageView设置圆角,按钮背景设置为透明。
self.imageView.layer.cornerRadius = cornerRadius;
self.imageView.layer.masksToBounds = YES;
具体代码:
@interface BGCommonButton : UIButton
@property (nonatomic, assign) NSInteger sno;
@property (nonatomic, copy) void (^hitBlock)(NSInteger sno);
- (id)initWithTitle:(NSString *)title titleColor:(UIColor *)titleColor icon:(UIImage *)icon smallIcon:(UIImage *)smallIcon cornerRadius:(CGFloat)cornerRadius sno:(NSInteger)sno frame:(CGRect)frame;
@end
- (id)initWithTitle:(NSString *)title titleColor:(UIColor *)titleColor icon:(UIImage *)icon smallIcon:(UIImage *)smallIcon cornerRadius:(CGFloat)cornerRadius sno:(NSInteger)sno frame:(CGRect)frame
{
self = [super initWithFrame:CGRectMake(0, 0, 12, 12)];
if (self)
{
// self.isSelect = NO;
self.icon = icon;
self.smallIcon = smallIcon;
self.titleColor = titleColor;
self.title = title;
self.cornerRadius = cornerRadius;
self.sno = sno;
self.frame = frame;
[self setTitle:getNotNilString(@"") forState:UIControlStateNormal];
if(self.smallIcon && title)
{
[self addSubview:self.decribeImageView];
[self addSubview:self.describeTitleLabel];
self.decribeImageView.frame = CGRectMake(COMMON_EDGE_DISTANCE, (self.frame.size.height - self.smallIcon.size.height - 13 -10)/2, self.smallIcon.size.width, self.smallIcon.size.height);
}
[self setImage:self.icon forState:UIControlStateNormal];
[self setImage:self.icon forState:UIControlStateHighlighted];
[self setImage:self.icon forState:UIControlStateSelected];
// [self setTitleColor:titleColor forState:(UIControlStateNormal)];
[self.imageView addCornerWithCornerRadius:cornerRadius];
self.imageView.layer.cornerRadius = cornerRadius;
self.imageView.layer.masksToBounds = YES;
[self addTarget:self action:@selector(didSelectAction:) forControlEvents:UIControlEventTouchUpInside];
}
// if (self = [super init]) {
// self = [[se alloc] init];
//
// }
return self;
}