博客> 自由画圆角——任意角
自由画圆角——任意角
2017-11-24 14:30 评论:0 阅读:592 ss流云ss
ios 圆角 任意圆角

/**

  • 设置部分圆角(相对布局)
  • @param corners 需要设置为圆角的角 UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight | UIRectCornerAllCorners
  • @param radii 需要设置的圆角大小 例如 CGSizeMake(20.0f, 20.0f)
  • @param rect 需要设置的圆角view的rect */

-(void)addRoundedCorners:(UIRectCorner)corners withRadii:(CGSize)radii viewRect:(CGRect)rect {

UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:radii];
CAShapeLayer* shape = [[CAShapeLayer alloc] init];
[shape setPath:rounded.CGPath];
self.layer.mask = shape;

} 比如要给图片画左上和左下的圆角

-(void)setPriceLabRadii{

self.priceLab = [[UILabel alloc]initWithFrame:CGRectMake(0,0, 100, 30)];
self.priceLab.text = [NSString stringWithFormat:@"%u元",arc4random() % 200 + 13];
self.priceLab.textColor = KWhiteColor;
self.priceLab.textAlignment = NSTextAlignmentCenter;
self.priceLab.font = [UIFont systemFontOfSize:12];
self.priceLab.backgroundColor = RGB(240, 91, 72);
//画圆角
[self.priceLab addRoundedCorners: UIRectCornerTopLeft | UIRectCornerBottomLeft withRadii:CGSizeMake((100/2.0,30/2.0) viewRect:CGRectMake(0, 0, self.priceLab.frame.size.width, self.priceLab.frame.size.height)];
self.priceLab.clipsToBounds = YES;
[self addSubview:self.priceLab];

}

收藏
2
sina weixin mail 回到顶部