ios 系统框架已经给我们提供了相应的切割圆角的方法, 但是如果在一个见面有很多控件切割的话会出现卡顿和个别不切得现在
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 UIButton * button = [UIButton buttonWithType:(UIButtonTypeSystem)]; [button setFrame:CGRectMake(100, 100, 100, 100)]; [self addSubview:button]; button.layer.cornerRadius = 10.0f; //弧度 button.layer.masksToBounds = YES; /** * * @param UIRectCorner * 左上 UIRectCornerTopLeft = 1 << 0, 左下 UIRectCornerBottomLeft = 1 << 2, 右下 UIRectCornerBottomRight = 1 << 3, 所有角 UIRectCornerAllCorners = ~0UL * */ UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:button.bounds.size]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init]; //设置大小 maskLayer.frame = button.bounds; //设置图形样子 maskLayer.path = maskPath.CGPath; button.layer.mask = maskLayer;注意: 如果这里选择两个角 的话如果是选两个对角线 则会切 所有角
比如:UIRectCornerTopLeft | UIRectCornerBottomRight 他就会切割所有角
当然你也可以直接创建个圆角的button
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://blog.csdn.net/qq_30402119/article/details/51499992