UITableView/UICollectionView section設(shè)置圓角 cell上控件設(shè)置圓角 UIView設(shè)置某個(gè)圓角

自定義UITableViewCell 上面的控件設(shè)置圓角 自定義cell的drawRect 方法,并在該方法里面設(shè)置圓角

-(void)drawRect:(CGRect)rect {

  [super drawRect:rect];

  self.avada.layer.cornerRadius = self.avada.width * 0.5;
  self.avada.layer.borderColor = [UIColor whiteColor].CGColor;
  self.avada.layer.borderWidth = 2;
  self.avada.layer.masksToBounds =  YES;
}

??section分組設(shè)置圓角

 // 1:tableview 分組圓角

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([cell respondsToSelector:@selector(tintColor)]) {
    //        if (tableView == self.tableView) {
    CGFloat cornerRadius = 10.f;
    cell.backgroundColor = UIColor.clearColor;
    CAShapeLayer *layer = [[CAShapeLayer alloc] init];
    CGMutablePathRef pathRef = CGPathCreateMutable();
    CGRect bounds = CGRectInset(cell.bounds, 10, 0);
    BOOL addLine = NO;
    if (indexPath.row == 0 && indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
        CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius);
    } else if (indexPath.row == 0) {

        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds));
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius);
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds));
        addLine = YES;
        
    } else if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1) {
        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
    } else {
        CGPathAddRect(pathRef, nil, bounds);
        addLine = YES;
    }
    layer.path = pathRef;
    CFRelease(pathRef);
    //顏色修改
    layer.fillColor = [UIColor colorWithWhite:1.f alpha:0.5f].CGColor;
    layer.strokeColor=[UIColor blackColor].CGColor;
    if (addLine == YES) {
        CALayer *lineLayer = [[CALayer alloc] init];
        CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
        lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+10, bounds.size.height-lineHeight, bounds.size.width-10, lineHeight);
        lineLayer.backgroundColor = tableView.separatorColor.CGColor;
        [layer addSublayer:lineLayer];
    }
    UIView *testView = [[UIView alloc] initWithFrame:bounds];
    [testView.layer insertSublayer:layer atIndex:0];
    testView.backgroundColor = UIColor.clearColor;
    cell.backgroundView = testView;
}
 //    }
}

2:collection 設(shè)置分組圓角

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{

 if ([cell respondsToSelector:@selector(tintColor)]) {
    //        if (tableView == self.tableView) {
    CGFloat cornerRadius = 6.f;
    cell.backgroundColor = UIColor.clearColor;
    CAShapeLayer *layer = [[CAShapeLayer alloc] init];
    CGMutablePathRef pathRef = CGPathCreateMutable();
    CGRect bounds = CGRectInset(cell.bounds, 10, 0);
    BOOL addLine = NO;

    //只設(shè)置最后一行圓角(如需要設(shè)置整個(gè)section為圓角,參考tableview Section 設(shè)置)
    if (indexPath.row == [collectionView numberOfItemsInSection:indexPath.section]-1 || (indexPath.row == 0 && indexPath.row == [collectionView numberOfItemsInSection:indexPath.section]-1)) {
        
        CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds));
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds), CGRectGetMidX(bounds), CGRectGetMaxY(bounds), cornerRadius);
        CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius);
        CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds));
    } else {//其他行為舉行
        CGPathAddRect(pathRef, nil, bounds);
        addLine = YES;
    }
    
    layer.path = pathRef;
    CFRelease(pathRef);
    
    //顏色修改
    layer.fillColor = [UIColor whiteColor].CGColor;
    layer.strokeColor=[UIColor clearColor].CGColor;
    
    if (addLine == YES) {
        
        CALayer *lineLayer = [[CALayer alloc] init];
        CGFloat lineHeight = (1.f / [UIScreen mainScreen].scale);
        lineLayer.frame = CGRectMake(CGRectGetMinX(bounds)+10, bounds.size.height-lineHeight, bounds.size.width-10, lineHeight);
        lineLayer.backgroundColor = BackgroundLightGray.CGColor;
        
        [layer addSublayer:lineLayer];
    }
    UIView *testView = [[UIView alloc] initWithFrame:bounds];
    [testView.layer insertSublayer:layer atIndex:0];
    testView.backgroundColor = BackGround_COLOR;
    cell.backgroundView = testView;
  }
}

??UIView設(shè)置某個(gè)圓角:以設(shè)置上面兩個(gè)為圓角例

//設(shè)置上面兩個(gè)為圓角
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: _contentView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(6,6)];
//創(chuàng)建 layer
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = _contentView.bounds;
//賦值
maskLayer.path = maskPath.CGPath;
_contentView.layer.mask = maskLayer;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末捉貌,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌吃沪,老刑警劉巖旺拉,帶你破解...
    沈念sama閱讀 219,110評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡漂辐,警方通過查閱死者的電腦和手機(jī)衡蚂,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,443評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門窿克,熙熙樓的掌柜王于貴愁眉苦臉地迎上來骏庸,“玉大人,你說我怎么就攤上這事让歼〕担” “怎么了?”我有些...
    開封第一講書人閱讀 165,474評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵谋右,是天一觀的道長(zhǎng)硬猫。 經(jīng)常有香客問我,道長(zhǎng)改执,這世上最難降的妖魔是什么啸蜜? 我笑而不...
    開封第一講書人閱讀 58,881評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮辈挂,結(jié)果婚禮上衬横,老公的妹妹穿的比我還像新娘。我一直安慰自己终蒂,他們只是感情好忆畅,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,902評(píng)論 6 392
  • 文/花漫 我一把揭開白布松捉。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪抗俄。 梳的紋絲不亂的頭發(fā)上誓酒,一...
    開封第一講書人閱讀 51,698評(píng)論 1 305
  • 那天咖为,我揣著相機(jī)與錄音柒凉,去河邊找鬼。 笑死债朵,一個(gè)胖子當(dāng)著我的面吹牛子眶,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播序芦,決...
    沈念sama閱讀 40,418評(píng)論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼臭杰,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了谚中?” 一聲冷哼從身側(cè)響起硅卢,我...
    開封第一講書人閱讀 39,332評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎藏杖,沒想到半個(gè)月后将塑,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,796評(píng)論 1 316
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡蝌麸,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,968評(píng)論 3 337
  • 正文 我和宋清朗相戀三年点寥,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片来吩。...
    茶點(diǎn)故事閱讀 40,110評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡敢辩,死狀恐怖蔽莱,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情戚长,我是刑警寧澤盗冷,帶...
    沈念sama閱讀 35,792評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站同廉,受9級(jí)特大地震影響仪糖,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜迫肖,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,455評(píng)論 3 331
  • 文/蒙蒙 一锅劝、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧蟆湖,春花似錦故爵、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,003評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至伦仍,卻和暖如春结窘,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背呢铆。 一陣腳步聲響...
    開封第一講書人閱讀 33,130評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留蹲缠,地道東北人棺克。 一個(gè)月前我還...
    沈念sama閱讀 48,348評(píng)論 3 373
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像线定,于是被迫代替她去往敵國(guó)和親娜谊。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,047評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫斤讥、插件纱皆、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,106評(píng)論 4 62
  • *面試心聲:其實(shí)這些題本人都沒怎么背,但是在上海 兩周半 面了大約10家 收到差不多3個(gè)offer,總結(jié)起來就是把...
    Dove_iOS閱讀 27,150評(píng)論 30 470
  • 轉(zhuǎn)載自:https://github.com/Tim9Liu9/TimLiu-iOS 目錄 UI下拉刷新模糊效果A...
    袁俊亮技術(shù)博客閱讀 11,928評(píng)論 9 105
  • 說好的今天有客人來吃飯,結(jié)果卻又說明天才能來芭商,公子仲還買了許多菜呢…… 不管他們派草,今天先做點(diǎn)嘗嘗——雞肉、火腿腸铛楣、...
    唐仲仁閱讀 175評(píng)論 0 0
  • 今天要寫的內(nèi)容是今天聽到的一本音頻書近迁,就是得到每天聽本書的音頻,書的名字是《重塑心靈》簸州,當(dāng)然是關(guān)于心理學(xué)的書籍鉴竭。之...
    踏上筆尖閱讀 177評(píng)論 0 0