按钮的image图片是非圆角,直接对UIButton设置圆角,iOS13系统没有圆角效果的问题及解决方案

简介: 按钮的image图片是非圆角,直接对UIButton设置圆角,iOS13系统没有圆角效果的问题及解决方案

按钮的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;
}
目录
相关文章
|
10月前
|
iOS开发
Cisco Catalyst 9800 Wireless Controller, IOS XE Release 17.17.1 ED - 思科无线控制器系统软件
Cisco Catalyst 9800 Wireless Controller, IOS XE Release 17.17.1 ED - 思科无线控制器系统软件
376 9
Cisco Catalyst 9800 Wireless Controller, IOS XE Release 17.17.1 ED - 思科无线控制器系统软件
|
5月前
|
安全 5G 语音技术
Cisco ASR 9000 Router IOS XR Release 7.11.2 MD - ASR 9000 系列聚合服务路由器系统软件
Cisco ASR 9000 Router IOS XR Release 7.11.2 MD - ASR 9000 系列聚合服务路由器系统软件
308 4
Cisco ASR 9000 Router IOS XR Release 7.11.2 MD - ASR 9000 系列聚合服务路由器系统软件
|
云安全 安全 Cloud Native
Cisco Catalyst 8000 Series IOS XE 17.18.1a ED 发布 - 思科边缘平台系列系统软件
Cisco Catalyst 8000 Series IOS XE 17.18.1a ED - 思科边缘平台系列系统软件
205 0
|
运维 监控 安全
Cisco ISR 4000 Series IOS XE 17.18.1a ED 发布 - 思科 4000 系列集成服务路由器 IOS XE 系统软件
Cisco ISR 4000 Series IOS XE 17.18.1a ED - 思科 4000 系列集成服务路由器 IOS XE 系统软件
253 0
|
人工智能 监控 安全
思科 Catalyst 9000 交换产品系列 IOS XE 系统软件 17.18.1 ED
Cisco Catalyst 9000 Series Switches, IOS XE Release 17.18.1 ED
251 0
|
安全 Android开发 数据安全/隐私保护
深入探索Android与iOS系统安全性的对比分析
在当今数字化时代,移动操作系统的安全已成为用户和开发者共同关注的重点。本文旨在通过比较Android与iOS两大主流操作系统在安全性方面的差异,揭示两者在设计理念、权限管理、应用审核机制等方面的不同之处。我们将探讨这些差异如何影响用户的安全体验以及可能带来的风险。
978 21
|
JavaScript 前端开发 iOS开发
ios样式开关按钮jQuery插件
ios样式开关按钮jQuery插件
225 7
|
安全 Android开发 iOS开发
深入探讨Android与iOS系统的差异及未来发展趋势
本文旨在深入分析Android和iOS两大移动操作系统的核心技术差异、用户体验以及各自的市场表现,进一步探讨它们在未来技术革新中可能的发展方向。通过对比两者的开放性、安全性、生态系统等方面,本文揭示了两大系统在移动设备市场中的竞争态势和潜在变革。
|
iOS开发
iOS调用系统通讯录
iOS调用系统通讯录
311 0
iOS调用系统通讯录