iphone - 使 UIView 的特定角变圆

标签 iphone ios uiview

我做了一些研究,发现没有简单的方法 UIView 圆的右上角和左上角,对吧?

附言。此代码使所有 4 个角变圆,这是 smth。我不想。

  #import <QuartzCore/QuartzCore.h>

 self.layer.cornerRadius = 5;
 self.layer.masksToBounds = YES;

最佳答案

你可以用这个片段来做:

// Set top right & left corners
[self setMaskTo:yourView byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight];

编辑

对不起,我忘记了

- (void)setMaskTo:(UIView*)view byRoundingCorners:(UIRectCorner)corners
{
    UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds
                                                  byRoundingCorners:corners
                                                        cornerRadii:CGSizeMake(8.0, 8.0)];
    CAShapeLayer *shape = [[CAShapeLayer alloc] init];
    [shape setPath:rounded.CGPath];    
    view.layer.mask = shape;
}

PS:正如我在评论中所说,如果您在显示 UITableViewCell 单元格时使用类似的东西,我发现使用背景图像总是更好的选择,因为这种绘图的东西总是影响性能。

关于iphone - 使 UIView 的特定角变圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14067897/

相关文章:

iphone - 覆盖 InputAccessoryView 时未调用模态视图析构函数

iphone - IOS Core蓝牙外设连接请求

swift - 关于如何在按住按钮时隐藏 View

iphone - UIView的-hitTest :withEvent: called three times?

iPhone 自动调整大小蒙版

iphone - MBProgressHUD UIWebView

iphone - 在启用弧的项目iOS中添加非弧库

iphone - NSMutableString appendString 生成一个 SIGABRT

ios - 不同屏幕尺寸的用户界面图像大小?

iphone - 从 View Controller 调用 poptoviewcontroller 函数