irpas技术客

[iOS开发小技巧] UIView单独切圆角,如只要左上右上两个圆角以及输入框提示语中间显示_马拉萨的春天_ios 切圆角

网络 4502

前言:ios开发中经常遇到一个view上只要两个圆角的情况。 1.切四个圆角的情况

view.layer.cornerRadius = 12; view.layer.masksToBounds = YES;

2.单独切圆角的情况,比如切左上、右上两个圆角

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH, 1000) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = self.bottomView.bounds; maskLayer.path = maskPath.CGPath; self.bottomView.layer.mask = maskLayer;

3. UITextField的提示语中间显示

? ? ? ? _nameTfd = [[UITextField alloc]initWithFrame:CGRectZero];

? ? ? ? _nameTfd.borderStyle = UITextBorderStyleNone;

? ? ? ? NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];

? ? ? ? style.alignment = NSTextAlignmentCenter;

? ? ? ? NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc]initWithString:@"请输入分类名称" attributes:@{NSParagraphStyleAttributeName:style}];

? ? ? ? _nameTfd.attributedPlaceholder = attribute;

? ? ? ? _nameTfd.backgroundColor = kRGBA(247, 248, 251, 1);

? ? ? ? _nameTfd.layer.masksToBounds = YES;

? ? ? ? _nameTfd.layer.cornerRadius = 21;

? ? ? ? _nameTfd.delegate = self;


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #iOS #切圆角