iOS-设置控件不同方位的圆角(OC & Swift)

    xiaoxiao2021-12-12  9

    前言:

    设置控件的圆角,包括有:

    没有圆角,全部圆角,上部圆角,下部圆角,左部圆角,右部圆角,左上圆角,右上圆角,左下圆角,左下圆角

    OC代码

    NSArray *titleArr = @[@"没有圆角",@"全部圆角",@"上部圆角",@"下部圆角",@"左部圆角",@"右部圆角",@"左上圆角",@"右上圆角",@"左下圆角",@"左下圆角"]; CGFloat space = 10; NSInteger lineCount = 4; CGFloat view_WID = (ScreenWidth - space * (lineCount + 1))/lineCount; for (int i = 0; i<10; i++) { UILabel *textLab = [[UILabel alloc]init]; textLab.textAlignment = NSTextAlignmentCenter; textLab.textColor = [UIColor redColor]; textLab.backgroundColor = [UIColor lightGrayColor]; textLab.frame = CGRectMake(space + (view_WID + space)*(i%lineCount), 100 + (view_WID + space)*(i/lineCount), view_WID, view_WID); textLab.text = titleArr[i]; [textLab setZFJGlobalViewWith:i cornerRadius:10.0]; [self.view addSubview:textLab]; }

    Swift代码

    let titleArr = ["没有圆角","全部圆角","上部圆角","下部圆角","左部圆角","右部圆角","左上圆角","右上圆角","左下圆角","左下圆角"] let space : Float = 10.0 let lineCount = 4 let view_WID : Float = (ScreenWidth - space * (Float(lineCount) + 1))/Float(lineCount) for i in stride(from: 0, to: 10, by: 1) { print("\(i)") let textLab = UILabel() textLab.textAlignment = NSTextAlignment.center textLab.textColor = UIColor.red textLab.backgroundColor = UIColor.lightGray let rect = CGRect(x: CGFloat(space + (view_WID + space)*Float(i%lineCount)), y: CGFloat(100 + (view_WID + space)*Float(i/lineCount)), width: CGFloat(view_WID), height: CGFloat(view_WID)) textLab.frame = rect textLab.text = titleArr[i] textLab .setZFJGlobalView(viewType: GlobalViewType(rawValue: i)!, cornerRadius: 10.0) self.view.addSubview(textLab) }

    效果图

    Demo下载

    http://download.csdn.net/detail/u014220518/9683593

    转载请注明原文地址: https://ju.6miu.com/read-900037.html

    最新回复(0)