美文网首页
控件的局部圆角化处理

控件的局部圆角化处理

作者: Felix的笔头 | 来源:发表于2018-06-01 16:52 被阅读0次
  以按钮为例 其他的也一样
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame =  CGRectMake(100, 100, 160, 40);
    [btn setBackgroundColor:[UIColor cyanColor]];
    [btn setTitle:@"这是一个按钮" forState:UIControlStateNormal];
    [self.view addSubview:btn];
    /**
     *  设置圆角
     */
     CGSize radio = CGSizeMake(5, 5);//圆角尺寸
    UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:btn.bounds byRoundingCorners:corner cornerRadii:radio];//这地方只能有bounds 使用frame 不可以
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//创建shapelayer
    masklayer.frame = btn.bounds;
    masklayer.path = path.CGPath;//设置路径
    btn.layer.mask = masklayer;

相关文章

网友评论

      本文标题:控件的局部圆角化处理

      本文链接:https://www.haomeiwen.com/subject/xgeksftx.html