按钮的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 系统打了个补丁——修复 iOS 16 系统键盘重大 Crash
我给 iOS 系统打了个补丁——修复 iOS 16 系统键盘重大 Crash
|
30天前
|
存储 Web App开发 Android开发
iOS不支持WebP格式图片解决方案和iPhone 7及其后硬件拍照的HEIC格式图片
iOS不支持WebP格式图片解决方案和iPhone 7及其后硬件拍照的HEIC格式图片
41 1
iOS不支持WebP格式图片解决方案和iPhone 7及其后硬件拍照的HEIC格式图片
|
30天前
iOS16系统根据PHAsset判断是否在云上
iOS16系统根据PHAsset判断是否在云上
25 1
|
30天前
|
安全 开发者 iOS开发
iOS16系统手机设置开启开发者模式才能安装ipa包
iOS16系统手机设置开启开发者模式才能安装ipa包
35 1
|
30天前
如何解决iOS16系统app首次启动总是弹出允许粘贴提示框问题
如何解决iOS16系统app首次启动总是弹出允许粘贴提示框问题
32 0
如何解决iOS16系统app首次启动总是弹出允许粘贴提示框问题
|
25天前
|
人工智能 vr&ar Android开发
安卓与iOS系统的发展趋势及影响分析
在移动互联网时代,安卓和iOS作为两大主流移动操作系统,在不断发展变化中展现出不同的特点和发展趋势。本文从技术性角度出发,分析了安卓和iOS系统的发展趋势,并探讨了它们对移动设备市场和用户体验的影响,帮助读者更好地理解当前移动操作系统的发展方向和未来可能的变化。
21 0
|
30天前
|
iOS开发
iOS13.6.1系统XR手机图文按钮显示不全问题
iOS13.6.1系统XR手机图文按钮显示不全问题
27 0
|
30天前
|
iOS开发
iOS16.1系统由于一个系统弹窗无法取消,导致屏幕卡死无法关机问题及解决方案
iOS16.1系统由于一个系统弹窗无法取消,导致屏幕卡死无法关机问题及解决方案
39 0
|
1月前
ios15从隐藏系统导航栏页面进入显示系统导航栏页面后,期望系统导航栏背景色为白色,但是导航栏背景变成黑色问题
ios15从隐藏系统导航栏页面进入显示系统导航栏页面后,期望系统导航栏背景色为白色,但是导航栏背景变成黑色问题
25 0
|
1天前
|
iOS开发 开发者 容器
探索iOS开发中的SwiftUI框架
【6月更文挑战第21天】本文深入探讨了苹果在iOS开发中推出的SwiftUI框架,旨在为开发者提供一种声明式、更简洁的界面设计方法。文章首先概述了SwiftUI的核心概念和优势,接着通过一个天气预报应用实例,详细讲解了如何使用SwiftUI进行布局和用户界面的设计。此外,还讨论了SwiftUI与UIKit的差异,以及如何将SwiftUI集成到现有的项目中。最后,文章展望了SwiftUI的未来发展方向,包括潜在的改进和新特性。