【问题标题】:Add a complex boarder to UIImageView向 UIImageView 添加复杂的边界
【发布时间】:2017-05-28 17:07:14
【问题描述】:

如何将下图(在 Objective-C 中)中的边界添加到 UIImageView。我尝试使用 UIBezierPath 但没有成功。

【问题讨论】:

  • “寄宿生”到底是什么意思?
  • 在代码中显示你的尝试。
  • uiimageview 是显示图片。你不应该覆盖它!使用 UIView 执行自定义绘图!请展示你的尝试!

标签: ios objective-c iphone uibezierpath


【解决方案1】:
  1. 创建一个 UIView(尺寸为正方形),添加角半径 = 其边的 1/2 倍。

  2. 现在将 UIImageView 作为子视图添加到此 UIView。

由于图像是圆形的,因此解决问题的更简单方法是在 UIVIew 中添加圆角半径。

下面是我使用的代码:

    let circleView: UIView = UIView(frame: CGRect(x: 0,
                                                  y: 0,
                                                  width: 100,
                                                  height: 100))
    circleView.center = view.center
    circleView.backgroundColor = .lightGray
    circleView.layer.cornerRadius = 50
    view.addSubview(circleView)
    

    let imageView: UIImageView = UIImageView(frame: CGRect(x: 0, 
                                                           y: 0, 
                                                           width: 100, 
                                                           height: 100))
    imageView.image = UIImage(named: "F8FIs.png")
    circleView.addSubview(imageView)

请注意,为了清晰起见,我在圆形视图中添加了浅灰色。

这是它的外观截图:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-19
    相关资源
    最近更新 更多