zoukankan      html  css  js  c++  java
  • iOS

    如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架)。而若要指定某几个角(小于4)为圆角而别的不变时,这种方法就不好用了。

    对于这种情况,Stackoverflow上提供了几种解决方案。其中最简单优雅的方案,就是使用UIBezierPath。下面给出一段示例代码。

    /* 指定UIView的某几个角为圆角
    
         * UIRectCornerTopLeft
    
         * UIRectCornerTopRight
    
         * UIRectCornerBottomLeft
    
         * UIRectCornerBottomRight
    
         * UIRectCornerAllCorners
    
        */
    
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(120, 120, 80, 80)];
    
        view.backgroundColor = [UIColor redColor];
    
        [self.view addSubview:view];
    
        
    
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
    
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    
        maskLayer.frame = view.bounds;
    
        maskLayer.path = maskPath.CGPath;
    
        view.layer.mask = maskLayer;
  • 相关阅读:
    hdu 2680(最短路)
    hdu 1548(最短路)
    hdu 1596(最短路变形)
    hdu 1546(dijkstra)
    hdu 3790(SPFA)
    hdu 2544(SPFA)
    CodeForces 597B Restaurant
    CodeForces 597A Divisibility
    CodeForces 598E Chocolate Bar
    CodeForces 598D Igor In the Museum
  • 原文地址:https://www.cnblogs.com/gongyuhonglou/p/8274695.html
Copyright © 2011-2022 走看看