按钮的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;
}
目录
相关文章
|
24天前
|
存储 安全 编译器
我给 iOS 系统打了个补丁——修复 iOS 16 系统键盘重大 Crash
我给 iOS 系统打了个补丁——修复 iOS 16 系统键盘重大 Crash
我给 iOS 系统打了个补丁——修复 iOS 16 系统键盘重大 Crash
|
12天前
|
前端开发 iOS开发
input框设置placeholder属性在iOS中显示不完整
input框设置placeholder属性在iOS中显示不完整
10 1
|
2月前
|
存储 Web App开发 Android开发
iOS不支持WebP格式图片解决方案和iPhone 7及其后硬件拍照的HEIC格式图片
iOS不支持WebP格式图片解决方案和iPhone 7及其后硬件拍照的HEIC格式图片
69 1
iOS不支持WebP格式图片解决方案和iPhone 7及其后硬件拍照的HEIC格式图片
|
13天前
|
安全 搜索推荐 Android开发
探索安卓和iOS系统的优劣与特点
在移动操作系统领域,安卓和iOS一直是最热门的两个选择。本文将探讨安卓和iOS系统的优劣与特点,帮助读者更好地了解这两个操作系统,并为选择合适的移动设备提供参考。
19 0
|
2月前
iOS16系统根据PHAsset判断是否在云上
iOS16系统根据PHAsset判断是否在云上
31 1
|
2月前
|
安全 开发者 iOS开发
iOS16系统手机设置开启开发者模式才能安装ipa包
iOS16系统手机设置开启开发者模式才能安装ipa包
46 1
|
2月前
如何解决iOS16系统app首次启动总是弹出允许粘贴提示框问题
如何解决iOS16系统app首次启动总是弹出允许粘贴提示框问题
36 0
如何解决iOS16系统app首次启动总是弹出允许粘贴提示框问题
|
2月前
|
人工智能 vr&ar Android开发
安卓与iOS系统的发展趋势及影响分析
在移动互联网时代,安卓和iOS作为两大主流移动操作系统,在不断发展变化中展现出不同的特点和发展趋势。本文从技术性角度出发,分析了安卓和iOS系统的发展趋势,并探讨了它们对移动设备市场和用户体验的影响,帮助读者更好地理解当前移动操作系统的发展方向和未来可能的变化。
24 0
|
2月前
|
iOS开发
iOS13.6.1系统XR手机图文按钮显示不全问题
iOS13.6.1系统XR手机图文按钮显示不全问题
37 0
|
2月前
|
iOS开发
iOS16.1系统由于一个系统弹窗无法取消,导致屏幕卡死无法关机问题及解决方案
iOS16.1系统由于一个系统弹窗无法取消,导致屏幕卡死无法关机问题及解决方案
71 0