【问题标题】:Round corners UIView or UIImageView圆角 UIView 或 UIImageView
【发布时间】:2011-12-29 15:14:13
【问题描述】:

我需要为UIImageView 添加圆角。我从论坛中找到了解决方案,并尝试了以下代码;

UIImageView * roundedView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"wood.jpg"]];
// Get the Layer of any view
CALayer * l = [roundedView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];

我使用的是 iOS 5,但找不到 setMasksToBounds:YESsetCornerRadius

那么还有其他方法可以让我的UIImageview 变圆吗?

【问题讨论】:

  • 您是否尝试过将l 分配回roundedView 的图层属性?
  • 怎么样?可以告诉我它的样子吗?
  • roundedView.layer = l;我没试过。

标签: iphone cocoa-touch uikit


【解决方案1】:

要在UIView(或其子类UIImageView)上制作圆角,您需要像您在问题中所写的那样在图层上设置cornerRadius。例如:

theRoundedCornersView.layer.cornerRadius = 10.0f;

导入正确的头文件,它会编译:

#import <QuartzCore/QuartzCore.h>

不要忘记通过将其添加到您的框架来链接它。

【讨论】:

    【解决方案2】:
    #import <QuartzCore/QuartzCore.h>
    

    并链接到 QuartzCore

    【讨论】:

      【解决方案3】:

      将此行添加到您的.h 文件中:

      #import <QuartzCore/QuartzCore.h>
      

      ...并且警告将消失(代码在没有导入的情况下仍然可以工作)。您的问题与 iOS 5 无关。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-08-26
        • 2010-12-03
        • 2011-12-04
        • 2015-11-02
        • 1970-01-01
        • 2013-05-15
        • 2011-01-24
        相关资源
        最近更新 更多