iOS开发之UITableviewCell实现两个圆角

本文介绍了如何在iOS开发中为UITableViewCell实现特定的圆角效果,特别是当cell作为section首尾时如何设置左上、右上、左下、右下四个角的圆角。分别详细讲解了两种方法:方法一通过自定义Cell子类实现,但存在滑动删除时的显示问题;方法二通过给背景视图添加mask来实现,解决了上述问题。
摘要由CSDN通过智能技术生成

坚持 成长 每日一篇

tableView时常有一个效果,就是当cell在section的第一个位置或者最后一行时,第一个cell左上角和右上角显示圆角,最后一个cell左下角和右下角显示圆角。

方法一

才用方法一可以实现圆角效果,但是如果table设置了滑动删除的话,第一行和最后一行滑动时候看不到删除按钮

如下面代码创建一个cell的子类
CornerTableViewCell.h

#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger,RoundCornerType)
{
    KKRoundCornerCellTypeTop,
    KKRoundCornerCellTypeBottom,
    KKRoundCornerCellTypeSingleRow,
    KKRoundCornerCellTypeDefault
};
@interface CornerTableViewCell : UITableViewCell
{
    CGFloat _cornerRadius;
}
@property(nonatomic,readwrite,assign)RoundCornerType roundCornerType;
-(id)initWithCornerRadius:(CGFloat)radius Style:(UITableViewCellStyle)tyle reuseIdentifier:(NSString*)identifier;
@end

CornerTableViewCell.m

#import "CornerTableViewCell.h"

@implementation CornerTableViewCell
-(id)initWithCornerRadius:(CGFloat)radius Style:(UITableViewCellStyle)tyle reuseIdentifier:(NSString*)identifier
{
    self = [super initWithStyle:tyle reuseIdentifier:identifier];
    if (self) {
        _cornerRadius = radius;
    }
    return self;
}
-(void)setFrame:(CGRect)frame
{
    [super setFrame:frame];
    UIBezierPath *path;
    switch (_roundCornerType) {
        case KKRoundCornerCellTypeTop: {
            path = [UIBezierPath bezierPathWithRoundedRect:self
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值